You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Parag Joshi <pa...@sungard.com> on 2012/05/25 07:58:57 UTC
How to check if sheet exist?
Hi,
I want to check whether given sheet (by name or number) exists in the file (xls
or xlsx) before I read it. I am using Event API to address memory footprint
issue and thus I don't want to use org.apache.poi.ss.usermodel.Workbook object.
Can someone please help me?
Thanks,
Parag
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: How to check if sheet exist?
Posted by Nick Burch <ni...@alfresco.com>.
On 25/05/12 06:58, Parag Joshi wrote:
> I want to check whether given sheet (by name or number) exists in the file (xls
> or xlsx) before I read it. I am using Event API to address memory footprint
> issue and thus I don't want to use org.apache.poi.ss.usermodel.Workbook object.
> Can someone please help me?
The way to check using the UserModel code is the same for the two formats.
However, you've asked about the Event API. These are much lower level,
so the differences between the two formats have to be handled by you as
there's nothing in between to hide them. (If you want an easy life, just
buy some more memory for your server and stick with the UserModel!)
For the .xls file format (HSSF), the details of the sheets are stored
near the top of the file. Start processing the file, and wait for the
BoundSheetRecord (sid=0x0085) to come past. When you've seen all of
those, you'll know if your sheet is in the file or not. If it is,
process as normal. If not, abort.
For the .xlsx file format (XSSF), open the file and grab the workbook
part (it's fairly small). Check that for what sheets exist, then decide
based on that if you want to process or not. If you're using XSSFReader,
call getWorkbookData() to get the Workbook part, then probably use
XmlBeans to process it.
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org