You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Liu, Mark" <li...@peacetech.com> on 2009/05/20 22:12:46 UTC

Insert Sheet into Workbook

Can't seem to find a way in insert a Sheet into a workbook.  Is there a work around for this?



Thanks,

Mark




Re: Insert Sheet into Workbook

Posted by MSB <ma...@tiscali.co.uk>.
You do not say which strand of POI you are using; HSSF or XSSF. So I am going
to assume you are using HSSF as that is the one I am most familiar with and,
even if not, I hope this points you in the right direction.

I have never tried this so let me explain my reasoning firstly please. The
HSSFWorkbook object holds references to 'it's' sheets in a List. So, even if
you add a sheet to an existing workbook, all you need to do is instruct the
workbook to move it to an appropriate position in this List. Assuming that
is true, take a look at the setSheetOrder(java.lang.String sheetname, int
pos) method defined on the HSSFWorkbook class. It seems to me that you will
need to do the following;

Open the workbook.
Create a new sheet and give it name.
Populate the sheet.
Call the setSheetOrder() method on the workbook, pass the name of the newly
created sheet and the position it should appear in - remember that positions
are zero based!

The third and fourth steps could of course be transposed as long as you hang
on to a reference for the sheet.

PS, I have just checked on the javadoc for the XSSFWorkbook class and the
same method does appear. This technique should work for both the binary and
OpenXML Excel files.



Liu, Mark wrote:
> 
> Can't seem to find a way in insert a Sheet into a workbook.  Is there a
> work around for this?
> 
> 
> 
> Thanks,
> 
> Mark
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Insert-Sheet-into-Workbook-tp23642646p23648977.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