Add borders to cells in POI generated Excel File

jzd picture jzd · Apr 19, 2011 · Viewed 103.6k times · Source

I am using POI to generate an Excel File. I need to add borders to specific cells in the worksheet.

How can I accomplish this?

Answer

jzd picture jzd · Apr 19, 2011

Setting up borders in the style used in the cells will accomplish this. Example:

style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
style.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);