When cells a merged, the border (bottom) style is not correct. I have produced 2 excel sheets, one with a normal cell and another with merged cells. Both have top and bottom style set. The merged cells bottom border is not defined, when going through the api, even when it is visible in excel.
using var plain1Stream = File.OpenRead(@"plain1.xlsx");
var wb1 = new Workbook(plain1Stream);
var ws1 = wb1.Worksheets[0];
var cell1 = ws1.Cells["A1"];
var style1 = cell1.GetStyle();
var borderTop1 = style1.Borders[BorderType.TopBorder];
var borderBottom1 = style1.Borders[BorderType.BottomBorder];
using var plain2Stream = File.OpenRead(@"plain2.xlsx");
var wb2 = new Workbook(plain2Stream);
var ws2 = wb2.Worksheets[0];
var cell2 = ws2.Cells["A1"];
var style2 = cell2.GetDisplayStyle();
var borderTop2 = style2.Borders[BorderType.TopBorder];
var borderBottom2 = style2.Borders[BorderType.BottomBorder]; // This one is incorrect
In the reply frame (after clicking “Reply” button), there is an “Upload” icon. Please zip your Excel files (first) and use this icon to upload your zipped archive(s).
Aspose.Cells is functioning correctly. You merged a range of two columns and three rows (A1:B3), and the original A1 cell did not have a border before merging. To confirm, please open your plain2.xlsx file in MS Excel and manually select the merged A1 cell. In the Home menu, click the “Merge & Center” combo button on the side and click “Unmerge Cells”. You will notice that there is no bottom border for A1 cell, so Aspose.Cells is providing the correct value.
Please let us know if you still have any issues or confusion.
Yes, you may check if the cell is merged and get the merged range, then evaluate the style/formatting. You may use these properties and methods for your needs. It should help you a bit.
Cell.IsMerged It will tell, if the cell is a merged cell or not.
Cell.GetMergedRange() If the cell is merged cell, it will return the merged range.
Worksheet.Cells.MergedCells It will return all the merged cells inside the worksheet.