You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by alamu <al...@yahoo.com> on 2009/04/23 21:58:39 UTC

setCellStyle (HSSFStyle) in poi-3.2-FINAL-20081019.jar throws exception

Hi,
Requirement: Copy the sheet from one workbook to another workbook. (which
includes copying format etc).

//code to fetch workbooks, sheets, rows, cells
HSSFCell oldCell, HSSFCell newCell; 
newCell.setCellStyle(oldCell.getCellStyle());

Old Jar: 
Using the old jar file (the version before poi-3.2-FINAL-20081019.jar) ,
implemented code to copy HSSFCell from one worksheet to another using the
above code.  It all worked fine.

New Jar: Upgraded to the new jar poi-3.2-FINAL-20081019.jar and the above
code throws the following exception:
"javax.servlet.ServletException: This Style does not belong to the supplied
Workbook. Are you trying to assign a style from one workbook to the cell of
a differnt workbook?"

Solution: If the above code should be replaced with some other
code(methods), can someone please clarify on how to implement copying
worksheet from one workbook to another without loosing the format/style etc. 

Thanks a lot!  Appreciate your help.




-- 
View this message in context: http://www.nabble.com/setCellStyle-%28HSSFStyle%29-in-poi-3.2-FINAL-20081019.jar-throws-exception-tp23198948p23198948.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: setCellStyle (HSSFStyle) in poi-3.2-FINAL-20081019.jar throws exception

Posted by alamu <al...@yahoo.com>.
Hi,
Thank you so much for the response, Nick.

Requirement:
a. Copy worksheets from one workbook to another workbook (including styles,
formats etc.)
b. After copying all sheets, make the sheets as protected except the first
worksheet.  First worksheet is user editable.

Protecting the worksheet (without protecting the workbook) works fine.  
But, if formats, styles etc. is applied to copying the worksheet and calling
the method protectSheet("") doesn't work.

Can anyone provide sample code or tell how to do the above.  
i) copy sheets from one workbook to another.  
ii) after copying, make the sheet as read-only.

Also, please let me know if the above CANNOT be done using POI.

Thanks again.



I think that you need to write protect the workbook as well. As I understand
the process, you need to call the sheet.protectSheet() method on each sheet
in the workbook and then the workbook.writeProtectWorkbook(java.lang.String
password, java.lang.String username) which, to quote the javadoc, "protect a
workbook with a password (not encypted, just sets writeprotect flags and the
password."



-- 
View this message in context: http://www.nabble.com/setCellStyle-%28HSSFStyle%29-in-poi-3.2-FINAL-20081019.jar-throws-exception-tp23198948p23259066.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: setCellStyle (HSSFStyle) in poi-3.2-FINAL-20081019.jar throws exception

Posted by MSB <ma...@tiscali.co.uk>.
I think that you need to write protect the workbook as well. As I understand
the process, you need to call the sheet.protectSheet() method on each sheet
in the workbook and then the workbook.writeProtectWorkbook(java.lang.String
password, java.lang.String username) which, to quote the javadoc, "protect a
workbook with a password (not encypted, just sets writeprotect flags and the
password."


alamu wrote:
> 
> Thank you so much for the response, Nick.
> 
> This is the requirement and having problems in implementation.
> 
> 1. Copy worksheet from one workbook to another workbook(including format,
> font etc)?
> 2. After the workbook is copied over, the sheet should be made readonly.
> (write protected).
> 
> I've tried different things for the above 2 features.  
> 
> a. Got the code from the following ((using only few methods - POI) to copy
> sheet from one workbook to another.  
> http://jxls.cvs.sourceforge.net/jxls/jxls/src/java/org/jxls/util/Util.java?view=markup
> 
> b. After copying sheets, called sheet.protectSheet method.
> 
> Feature a) works but not the feature b)
> 
> Questions:
> a. For the above, what version of the POI should be used? 
> b. Can someone please let me know if the above features are supported with
> POI?  If so, can someone please provide some sample code?
> 
> Please let me know if you have questions on the above.  Any help is much
> appreciated.
> 
> 

-- 
View this message in context: http://www.nabble.com/setCellStyle-%28HSSFStyle%29-in-poi-3.2-FINAL-20081019.jar-throws-exception-tp23198948p23229246.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: setCellStyle (HSSFStyle) in poi-3.2-FINAL-20081019.jar throws exception

Posted by alamu <al...@yahoo.com>.
Thank you so much for the response, Nick.

This is the requirement and having problems in implementation.

1. Copy worksheet from one workbook to another workbook(including format,
font etc)?
2. After the workbook is copied over, the sheet should be made readonly.
(write protected).

I've tried different things for the above 2 features.  

a. Got the code from the following ((using only few methods - POI) to copy
sheet from one workbook to another.  
http://jxls.cvs.sourceforge.net/jxls/jxls/src/java/org/jxls/util/Util.java?view=markup

b. After copying sheets, called sheet.protectSheet method.

Feature a) works but not the feature b)

Questions:
a. For the above, what version of the POI should be used? 
b. Can someone please let me know if the above features are supported with
POI?  If so, can someone please provide some sample code?

Please let me know if you have questions on the above.  Any help is much
appreciated.

-- 
View this message in context: http://www.nabble.com/setCellStyle-%28HSSFStyle%29-in-poi-3.2-FINAL-20081019.jar-throws-exception-tp23198948p23226546.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: setCellStyle (HSSFStyle) in poi-3.2-FINAL-20081019.jar throws exception

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 23 Apr 2009, alamu wrote:
> Requirement: Copy the sheet from one workbook to another workbook. (which
> includes copying format etc).
>
> //code to fetch workbooks, sheets, rows, cells
> HSSFCell oldCell, HSSFCell newCell;
> newCell.setCellStyle(oldCell.getCellStyle());

This won't work, and never has. A recent change was to flag up that what 
you've tried to is invalid. Please see the javadocs. What you'll actually 
want is HSSFCellStyle.cloneStyleFrom:
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html#cloneStyleFrom(org.apache.poi.hssf.usermodel.HSSFCellStyle)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org