You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Zongquan Liu <zo...@cisco.com> on 2012/02/14 09:59:29 UTC
How to set the background color of a cell? why my code can't work... I need some help!
Hi all,
I use POI 3.7 to create Excel files. However, when I decide to set the
background of the Excel file with following code:
FileInputStream ins = new FileInputStream(new
File("/driver/dir/myfile.xls"));
Workbook wb = new HSSFWorkbook(ins);
for(int i=0; i< wb.getNumberOfSheets();i++){
Sheet sheet = wb.getSheetAt(i);
if(sheet!=null){
Row row = sheet.getRow(0);
Iterator<Cell> ct = row.iterator();
while(ct.hasNext()){
Cell cell = (Cell) ct.next();
if(cell!=null){
HSSFCellStyle hssfstyle = (HSSFCellStyle)
cell.getCellStyle();
hssfstyle.setFillBackgroundColor(HSSFColor.YELLOW.index);
hssfstyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
cell.setStyle(hssfstyle);
}
}
}
}
Thanks
-Zongquan Liu
-----Original Message-----
From: Thomas Sommer [mailto:thomas.sommer@gmx.de]
Sent: Tuesday, February 14, 2012 6:24 AM
To: POI Users List
Subject: Re: Read-only access to workbook with protected structure and
window
I did it.
With POI 3.8 beta 5 it's possible to open protected xls-file for reading
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org