You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Thomas Sommer <th...@gmx.de> on 2012/02/08 06:34:28 UTC
Read-only access to workbook with protected structure and window
How can I open a workbook (Excel 2003) read-only when the structure and window of the workbook are protected?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
How to set the background color of a cell? why my code can't work... I need some help!
Posted by Zongquan Liu <zo...@cisco.com>.
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
Re: How to set the background color of a cell? why my code can't
work... I need some help!
Posted by Yegor Kozlov <ye...@dinom.ru>.
You need to set foreground color, not background.
Also, create a cell style outside of the loop:
CellStyle sytle = wb.createCellStyle();
style.setFillForegroundColor(HSSFColor.YELLOW.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
and then assign it to the cells:
while(ct.hasNext()){
Cell cell = (Cell) ct.next();
cell.setCellStyle(style);
}
Yegor
On Tue, Feb 14, 2012 at 1:00 PM, Zongquan Liu <zo...@cisco.com> wrote:
> the background color doesn't change when I write the workbook to my native
> file!
>
> Thanks
> -Zongquan Liu
>
>
> -----Original Message-----
> From: Zongquan Liu [mailto:zoliu@cisco.com]
> Sent: Tuesday, February 14, 2012 4:59 PM
> To: 'POI Users List'
> Subject: 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: How to set the background color of a cell? why my code can't work... I need some help!
Posted by Zongquan Liu <zo...@cisco.com>.
the background color doesn't change when I write the workbook to my native
file!
Thanks
-Zongquan Liu
-----Original Message-----
From: Zongquan Liu [mailto:zoliu@cisco.com]
Sent: Tuesday, February 14, 2012 4:59 PM
To: 'POI Users List'
Subject: 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
Re: Read-only access to workbook with protected structure and window
Posted by Thomas Sommer <th...@gmx.de>.
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
Re: Read-only access to workbook with protected structure and window
Posted by Thomas Sommer <th...@gmx.de>.
Seems like it's not supported.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52142
On Wednesday 08 February 2012 06:34:28 Thomas Sommer wrote:
> How can I open a workbook (Excel 2003) read-only when the structure and window of the workbook are protected?
>
> ---------------------------------------------------------------------
> 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