You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Wakebrad <br...@hotmail.com> on 2007/09/07 00:44:08 UTC

Selecting a specific worksheet to parse in event model HSSF?

Using HSSFListener I have successfully parsed the first worksheet in a
workbook and all worksheets in the workbook but now my users want to be able
to select which worksheet in the workbook they want to import. Is there a
way to get the names of the worksheets and declare which worksheet to parse
using the event model. I can't find a way to get an inputstream from an
HSSFSheet or a way to retrieve a sheet from the POIFSFileSystem.

Thanks.

			POIFSFileSystem poifs = new POIFSFileSystem(excelFileStream);
			// get the Workbook (excel part) stream in a InputStream
			InputStream din = poifs.createDocumentInputStream("Workbook");
			// construct out HSSFRequest object
			HSSFRequest req = new HSSFRequest();
			// lazy listen for ALL records with the listener shown above
			req.addListenerForAllRecords(this);
			// create our event factory
			HSSFEventFactory factory = new HSSFEventFactory();
			// process our events based on the document input stream
			factory.processEvents(req, din);
			din.close();

-- 
View this message in context: http://www.nabble.com/Selecting-a-specific-worksheet-to-parse-in-event-model-HSSF--tf4395114.html#a12532881
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: Selecting a specific worksheet to parse in event model HSSF?

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 6 Sep 2007, Wakebrad wrote:
> Is there a way to get the names of the worksheets and declare which
> worksheet to parse using the event model. I can't find a way to get an
> inputstream from an HSSFSheet or a way to retrieve a sheet from the
> POIFSFileSystem.

Not easily, no. IIRC, the excel OLE2 stream will contain all your sheets.

What you'll probably need to do is process your document twice. On the
first parse, grab all the sheet records, and offer up the list to your
users (you probably want the BoundSheetRecords). On the 2nd pass, wait
until your sheet of interest, then grab the data until the next one.

As a starting point, I'd suggest baseing some code on
org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener
and uncommenting all the print statements, so you can see the record
structure

Nick

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


Util.copySheets

Posted by "Lee, Jun S." <Ju...@tellabs.com>.
I am having some issues while copying sheets using Util.copySheets()

I dynamically create columns in a sheet and copy the sheet to a
different sheet belong to a different workbook.  When I do this, I
seemed to be getting the default column width problem mentioned below in
an earlier thread.

I can confirm that dynamic column population works if I don't use
copySheets and save the original workbook.

I tried manually calling setDefaultColumn() on the newssheet before
Util.copySheets() but no luck.

Please let me know if there's anything I can do.


Thanks,
Jun






Re: [jXLS-user] Dynamic Column Ouput Hidden
From: Leo <le...@gm...> - 2007-07-11 20:56
Hi Masaki,

This is a bug which happens because of specific behaviour of POI
HSSFSheet
getColumnWidth() method in case if columns have default column width.
The easiest way for you to fix it is to change default column width in
template.
So just try to resize excel columns in a template a bit (1 pixel
should be enough ).

Also I have made a change in SVN jXLS code that should fix this.
So the latest SVN code should resolve this issue automatically and
default column widths should work fine.

Any feedback would be appreciated.

Thanks,
Leo

Wednesday, July 11, 2007, 1:14:31 PM, you wrote:

> Hi,

> This could be a bug, but I'm not sure.
> When I try to create dynamic columns with jx:forEach,
> all the columns are hidden in the output Excel.

> What I did is as simple as this:
> 1st row, 1st column:
> <jx:forEach items="${cols}" var="col">
> 1st row, 2nd column:
> ${col.text}
> 1st row, 3rd column:
> </jx:forEach>

> data is output correctly, but all columns are hidden.

> Masaki
============================================================
The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader
of this message is not the intended recipient, or an employee
or agent responsible for delivering this message to the
intended recipient, you are hereby notified that any reproduction,
dissemination or distribution of this communication is strictly
prohibited. If you have received this communication in error,
please notify us immediately by replying to the message and
deleting it from your computer. Thank you. Tellabs
============================================================

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


Re: Selecting a specific worksheet to parse in event model HSSF?

Posted by ap...@charter.net.
Unless someone has any other ideas, you will need to parse the file into an HSSFWorkbook and then use wb.getSheet(String) using the sheet's name or wb.getSheetAt(int) using the sheet's index (0-based) to get the appropriate sheet from the workbook.  That is the only way I have done this in the past.
---- Wakebrad <br...@hotmail.com> wrote: 
> 
> Using HSSFListener I have successfully parsed the first worksheet in a
> workbook and all worksheets in the workbook but now my users want to be able
> to select which worksheet in the workbook they want to import. Is there a
> way to get the names of the worksheets and declare which worksheet to parse
> using the event model. I can't find a way to get an inputstream from an
> HSSFSheet or a way to retrieve a sheet from the POIFSFileSystem.
> 
> Thanks.
> 
> 			POIFSFileSystem poifs = new POIFSFileSystem(excelFileStream);
> 			// get the Workbook (excel part) stream in a InputStream
> 			InputStream din = poifs.createDocumentInputStream("Workbook");
> 			// construct out HSSFRequest object
> 			HSSFRequest req = new HSSFRequest();
> 			// lazy listen for ALL records with the listener shown above
> 			req.addListenerForAllRecords(this);
> 			// create our event factory
> 			HSSFEventFactory factory = new HSSFEventFactory();
> 			// process our events based on the document input stream
> 			factory.processEvents(req, din);
> 			din.close();
> 
> -- 
> View this message in context: http://www.nabble.com/Selecting-a-specific-worksheet-to-parse-in-event-model-HSSF--tf4395114.html#a12532881
> 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
> 


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