You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by fsicher <fs...@gmail.com> on 2011/09/27 09:27:52 UTC

Insert a XSSFSheet form XSSFWorkbook 'a' into XSSFWorkbook 'b'

I've two XSSFWorkbooks: *a* and *b*. For some reason I want to copy one or
more Sheets from *a* into *b*. My solution is, that I create (one or more)
XSSFSheet(s) in *b* and copy rows and cells (iterator) from corresponding
*a*-Sheet into *b*-Sheet. 

Ist it possible to copy the *a*-Sheet as an whole Object? 

Something like this:

- open both Workbooks
- clone a-Sheets that should be copied into *a*-Workbook
- call setSheetOrder (String sheetName, int pos) to insert cloned Sheets
into *a*-Workbook.

I've tried it, but it doesn't work. 

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Insert-a-XSSFSheet-form-XSSFWorkbook-a-into-XSSFWorkbook-b-tp4844338p4844338.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: Insert a XSSFSheet form XSSFWorkbook 'a' into XSSFWorkbook 'b'

Posted by fsicher <fs...@gmail.com>.
Thanks, Nick.

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Insert-a-XSSFSheet-form-XSSFWorkbook-a-into-XSSFWorkbook-b-tp4844338p4846484.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: Insert a XSSFSheet form XSSFWorkbook 'a' into XSSFWorkbook 'b'

Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 27 Sep 2011, fsicher wrote:
> I've two XSSFWorkbooks: *a* and *b*. For some reason I want to copy one or
> more Sheets from *a* into *b*. My solution is, that I create (one or more)
> XSSFSheet(s) in *b* and copy rows and cells (iterator) from corresponding
> *a*-Sheet into *b*-Sheet.
>
> Ist it possible to copy the *a*-Sheet as an whole Object?

Alas not, as not all the things a sheet references are actually stored at 
the sheet level. Some parts are workbook wide. Thus, if you copied just 
the sheet parts, it wouldn't work as you'd be missing things (or worse 
referencing the wrong things!)

The only safe way is to iterate over the rows and cells, and copy over 
styles and names as you spot new ones

Nick

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