Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add borders to cells in POI generated Excel File

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?

like image 397
jzd Avatar asked Apr 19 '11 17:04

jzd


2 Answers

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); 
like image 140
jzd Avatar answered Sep 22 '22 12:09

jzd


In the newer apache poi versions:

XSSFCellStyle style = workbook.createCellStyle(); style.setBorderTop(BorderStyle.MEDIUM); style.setBorderBottom(BorderStyle.MEDIUM); style.setBorderLeft(BorderStyle.MEDIUM); style.setBorderRight(BorderStyle.MEDIUM); 
like image 37
Mathias G. Avatar answered Sep 22 '22 12:09

Mathias G.