Free Support Forum - aspose.com

Merged cell borders information

Hi.

I have found, that library returns invalid borders style state for merged cells. For example in attached document we have a cell “B2”, that has 4 medium borders, but when i try to check it via library, i receive only left and top border. Excel shows that cell has 4 borders.

    @Test
public void test() throws Exception {
    Workbook wb = new Workbook("D://in.xlsx");

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

    Cell cell = cells.get("B2");

    Style style = cell.getDisplayStyle();

    System.out.println(style.getBorders().getByBorderType(BorderType.LEFT_BORDER).getLineStyle());
    System.out.println(style.getBorders().getByBorderType(BorderType.TOP_BORDER).getLineStyle());
    System.out.println(style.getBorders().getByBorderType(BorderType.RIGHT_BORDER).getLineStyle());
    System.out.println(style.getBorders().getByBorderType(BorderType.BOTTOM_BORDER).getLineStyle());
}

in.zip (5.7 KB)

@makarovalv,

Thanks for the template file and sample code.

After an initial test, I am able to observe the issue as you mentioned by using your sample code with your template file. I found that some invalid borders style states returned for merged cells. For example, a merged cell, i.e., “B2” has 4 medium borders, but when we try to check it via Aspose.Cells APIs, we receive only left and top borders. I guess we got to get/evaluate the relevant individual cells in the merged range (e.g B3…G3, C2…G2) and check their borders for right/bottom borders, etc.
e.g
Sample code:

            Workbook wb = new Workbook("D://in.xlsx"); 

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

            Cell cell = cells.get("B2"); 

            Style style = cell.getDisplayStyle(); 

            System.out.println(style.getBorders().getByBorderType(BorderType.LEFT_BORDER).getLineStyle());//2 - Ok 
            System.out.println(style.getBorders().getByBorderType(BorderType.TOP_BORDER).getLineStyle());//2 - Ok 
            System.out.println(style.getBorders().getByBorderType(BorderType.RIGHT_BORDER).getLineStyle());//0 - Not Ok 
System.out.println(style.getBorders().getByBorderType(BorderType.BOTTOM_BORDER).getLineStyle());//0 - Not Ok 

I have logged a ticket with an id “CELLSJAVA-42611” for your issue. We will check and investigate if we could fix the issue or there is some other way around to cope with it.

@makarovalv,

We could not support this feature for performance grounds. Please get the range by Cell.getMergedRange(), then get the border by each cell by yourself.