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

Free Support Forum - aspose.com

Get Border Styles

I’m creating a .xlsx file parser, specifically I’m trying to read the border styles of a specific cell.

cells.get(i,j).getDisplayStyle().getBorders() seems to give me “Diagonal Styles”, but these “Diagonal Styles” don’t seem to correlate with any border styles.

What am I misunderstanding?

Hi Nicolas,

Thank you for contacting Aspose support.

You can use the following piece of code to determine which type of borders have been applied to the cell.

By the way, I haven’t understood the statement “Diagonal Styles don’t seem to correlate with any border styles.”. Did you mean that your spreadsheet does not have the diagonal border applied to the specified cell or you are not able to find it in Excel’s Format Cells dialog?


Workbook book = new Workbook(dir + “book1.xlsx”);
Worksheet sheet1 = book.getWorksheets().get(0);
Cells cells1 = sheet1.getCells();
Style style = cells1.get(“A1”).getDisplayStyle();
System.out.println("BOTTOM_BORDER " + style.isModified(StyleModifyFlag.BOTTOM_BORDER));
System.out.println("TOP_BORDER " + cells1.get(“A1”).getDisplayStyle().isModified(StyleModifyFlag.TOP_BORDER));
System.out.println("LEFT_BORDER " + style.isModified(StyleModifyFlag.LEFT_BORDER));
System.out.println("RIGHT_BORDER " + style.isModified(StyleModifyFlag.RIGHT_BORDER));
System.out.println("DIAGONAL_DOWN_BORDER " + style.isModified(StyleModifyFlag.DIAGONAL_DOWN_BORDER));
System.out.println("DIAGONAL_UP_BORDER " + style.isModified(StyleModifyFlag.DIAGONAL_UP_BORDER));

Can you elaborate on where “StyleModifyFlag.BOTTOM_BORDER” comes from?

How does the styleFlag know which cell I’m referring to?

How can I get border styles? i.e. weight, color, etc.

Hi again,

Please note, Style.isModified method needs a reference of the type of formatting which we need to inquire. In order to do so, we pass on the appropriate value from StyleModifyFlag class to the Style.isModified method. In this scenario you wish to retrieve the information about borders therefore we have used the LeftBorder, BottomBorder etc.

Regarding the second part of your inquiry, if you check the code snippet provided in my previous post, you will notice that the Style object was retrieved from an instance of Cell, that means, the Style object is already associated with the Cell object therefore all further inquiries will be in the same context.

If you wish to retrieve the color or line style of the border then you can do it as follow. Please note, the Border.LineStyle property returns an integer value which corresponds to the CellBorderType class. Moreover, custom line weight neither can be set nor retrieved using Aspose.Cells APIs.

Please check the following documents for your kind reference.


Workbook book = new Workbook(dir + “book1.xlsx”);
Worksheet sheet1 = book.getWorksheets().get(0);
Cells cells1 = sheet1.getCells();
Style style = cells1.get(“A2”).getDisplayStyle();
Border border = style.getBorders().getByBorderType(BorderType.BOTTOM_BORDER);
System.out.println(border.getColor() + " " + border.getLineStyle());

Where does “BorderType.BOTTOM_BORDER” get defined?

Sorry if this is a dumb question, I’m new to java.

Hi Nicolas,

Please note, the BorderType class contains the constants to define the borders a cell (or a range of cells) could have, whereas the BOTTOM_BORDER represents the bottom border, that is the common border between the two adjacent cells.

Please feel free to contact us back in case you have any further questions or concerns.