Borders in Excel using Apache POI

In some previous posts we have seen how we can create excel and also add various fonts to the excel file using Apache POI.
Now we will see how to add borders in excel using Apache POI.

Simple Borders

Border are added here per cell, so similar to fonts we need to create a CellStyle that has the desired borders and then add that CellStyle to the required cell.

In the above code we have added various styles to a single cell style for all the directions of the border.
There are many more styles that can be added to the border. Some of the examples are

Colors to the Border

We can also add colors to the Border.
We need to add the colors to the specific border on the CellStyle.

Sample Code: Borders in Excel using Apache POI

Lets see a Sample code where we create a excel file, add a row and cell and then add borders and colors to that cell.

Borders in Excel using Apache POI