Missing cell Border on merged cells

Hi,

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

TIA, Frank

@Frank_Nielsen,

Could you please zip and attach both XLSX files? We will evaluate your issue soon.

How/Where do i attach files?

@Frank_Nielsen,

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).

test.zip (12.1 KB)

Here you go

@Frank_Nielsen,

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.

Correct, if they are unmerged.

But when they are merged, you set the style as it was 1 cell. Same goes for font, color and all other styling. Excel treat merged cells a one cell.

So to follow you answer; i have to “calculate” my way to the get bottom border color of A3 or B3 ?

@Frank_Nielsen,

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.

@Frank_Nielsen
Please call Cell.GetDisplayStyle(true) to get cell border on merged cells.

1 Like

Thanks, that was the trick :smiley:

@Frank_Nielsen
You are welcome. If you have any questions, please feel free to contact us.