We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set Border for merged cells

Hi. I found, that set border for merged cells not working properly:

un.png (2.7 KB)
@Test
public void setBorderTest() throws Exception {
Workbook wb = new Workbook();

    Cells cells = wb.getWorksheets().get(0).getCells();

    cells.merge(1, 1, 3, 3);

    Style style = cells.get(1, 1).getStyle();
    style.setBorder(BorderType.TOP_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));
    style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));
    style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));
    style.setBorder(BorderType.LEFT_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));
    cells.get(1, 1).setStyle(style);

    wb.save("D://out.xlsx");
}

Result you can see on picture. I marked red squares missed borders.

Best regards. Alexey

@makarovalv,

Thanks for providing us sample code and screenshot.

When you apply borders to merged cell, you will apply border (in the merged range of cells) in the following way, see the following sample code for your reference:
e.g
Sample code:

Workbook wb = new Workbook();

    Cells cells = wb.getWorksheets().get(0).getCells();

    cells.merge(1, 1, 3, 3);

    cells.get(1, 1).getMergedRange().setOutlineBorder(BorderType.TOP_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));
    cells.get(1, 1).getMergedRange().setOutlineBorder(BorderType.RIGHT_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));
    cells.get(1, 1).getMergedRange().setOutlineBorder(BorderType.BOTTOM_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));
    cells.get(1, 1).getMergedRange().setOutlineBorder(BorderType.LEFT_BORDER, CellBorderType.MEDIUM, Color.fromArgb(0));

    wb.save("out1.xlsx");

Let us know if I can be of any further help.