Working with Borders in Apache POI and Aspose.Cells

Aspose.Cells - Working with Borders

Aspose.Cells provides a class, Workbook that represents a Microsoft Excel file. The Workbook class contains a WorksheetCollection that allows access to each worksheet in the Excel file. A worksheet is represented by the Worksheet class. The Worksheet class provides a Cellscollection. Each item in the Cells collection represents an object of the Cell class.

Aspose.Cells provides the setStyle method in the Cell class used to set a cell’s formatting style. Also, the Style object of the Style class is used and provides properties for configuring font settings.


 // Style the cell with borders all around.

Style style = workbook.createStyle();

style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());

style.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getGreen());

style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlue());

style.setBorder(BorderType.TOP_BORDER, CellBorderType.MEDIUM_DASH_DOT, Color.getBlack());

// Setting style to the cell


Apache POI SS - HSSF XSSF - Working with Borders

CellStyle class provides features to set borders settings using Apache POI SS - HSSF and XSSF.


 //Setting the line of the top border


//Setting the line of the bottom border


//Setting the line of the left border


//Setting the line of the right border


//Saving the modified style to the "A1" cell.


Download Running Code

Download Sample Code