Hi.
Well, I’m not really trying to merge cells which are already merged, but Aspose.Cells tells me I’m doing so! This is a part of code facing error:
ws.Cells(cri, 0).Value = als(j).QGroup.DisplayOrder
rng = ws.Cells.CreateRange(cri, 0, als(j).QGroup.Questions.Count, 1)
rng.Merge()
And this is output error message:
Cells in range A9:A11 cannot be merged because cells in range A10:H10 have already been merged.
at ..Merge(Cells , Int32 , Int32 , Int32 , Int32 )
at Aspose.Cells.Cells.Merge(Int32 firstRow, Int32 firstColumn, Int32 totalRows, Int32 totalColumns)
at Aspose.Cells.Range.Merge()
at PAWeb.GAPersonalResultsCentral.DoGenerateReport(Object sender, EventArgs e) in C:\Users\Administrator\documents\visual studio 2013\Projects\Performance Appraizal\Performance Appraizal Web\Level05\GeneralAppraisal\GAPersonalResultsCentral.aspx.vb:line 665
When I remove merge command (line 665, as displayed above), I receive attached excel file. I couldn’t figure out cell A10 (which seems to be the cause of error) is merged with which of the other cells. It seems to be completely alone! And more strange, A10:H10 is not merged at all! (C10:H10 is merged, however) Some lines forward, I have another merge command which tries to merge B9:B11 and I receive the same error because A10:H10 is already merged! Does anyone have any idea about this?
EDIT: I was working on color styles and found that the above code block (which contains color formatting after merge) does strange things. I put a message box to find out which cell range every rng variable refers to, and reached A9:A11, A12:A15, A16:A17, A18 (alone) and so on. This is what I need, but when I apply colors and other formatting, merged ranges A37:H37, A38:L38, A:39, B39 and some other cells are also affected! Complete code:
ws.Cells(cri, 0).Value = als(j).QGroup.DisplayOrder
rng = ws.Cells.CreateRange(cri, 0, als(j).QGroup.Questions.Count, 1)
'rng.Merge()
st = wb.CreateStyle
st.Font.Name = “B Nazanin”
st.Font.Size = 11
st.HorizontalAlignment = Cells.TextAlignmentType.Center
st.VerticalAlignment = Cells.TextAlignmentType.Center
st.Borders.SetColor(System.Drawing.Color.Black)
st.Borders.SetStyle(Cells.CellBorderType.Thin)
st.Borders.DiagonalStyle = Cells.CellBorderType.None
rng.SetStyle(st)
ws.Cells(cri, 1).Value = als(j).QGroup.Name
rng = ws.Cells.CreateRange(cri, 1, als(j).QGroup.Questions.Count, 1)
'rng.Merge()
st = wb.CreateStyle
st.Font.Name = “B Nazanin”
st.Font.Size = 11
st.VerticalAlignment = Cells.TextAlignmentType.Center
st.Borders.SetColor(System.Drawing.Color.Black)
st.Borders.SetStyle(Cells.CellBorderType.Thin)
st.Borders.DiagonalStyle = Cells.CellBorderType.None
rng.SetStyle(st)
And program output excel file besides expected one is attached.