You seem frustrated. If so, you have my sincere apologies,
my goal was to make the documentation so good that others wouldn't
be as frustrated as I get using most opensource software due to
lack of documentation.
However, I'm not entirely sure you have the correct version
of the howto.
A couple clarifications. The evenmodel api only appears in the
development builds (its a feature included in this cycle).
The HOWTO includes a code sample and these passages:
----------------------------------------------------------------------------
The event API is brand new. It is intended for intermediate developers
who are willing to learn a little bit of the low level API structures.
Its relatively simple to use, but requires a basic understanding of the
parts of an Excel file (or willingness to learn). The advantage provided
is that you can read an XLS with a relatively small memory footprint.
To use this API you construct an instance of
org.apache.poi.hssf.eventmodel.HSSFRequest. Register a class you create
that supports the org.apache.poi.hssf.eventmodel.HSSFListener interface
using the HSSFRequest.addListener(yourlistener, recordsid). The
recordsid should be a static reference number (such as BOFRecord.sid)
contained in the classes in org.apache.poi.hssf.record. The trick is you
have to know what these records are. Alternatively you can call
HSSFRequest.addListenerForAllRecords(mylistener). In order to learn
about these records you can either read all of the javadoc in the
org.apache.poi.hssf.record package or you can just hack up a copy of
org.apache.poi.hssf.dev.EFHSSF and adapt it to your needs. TODO: better
documentation on records.
Once you've registered your listeners in the HSSFRequest object you can
construct an instance of org.apache.poi.poifs.filesystem.FileSystem (see
POIFS howto) and pass it your XLS file inputstream. You can either pass
this, along with the request you constructed, to an instance of
HSSFEventFactory via the HSSFEventFactory.processWorkbookEvents(request,
Filesystem) method, or you can get an instance of DocumentInputStream
from Filesystem.createDocumentInputStream("Workbook") and pass it to
HSSFEventFactory.processEvents(request, inputStream). Once you make this
call, the listeners that you constructed receive calls to their
processRecord(Record) methods with each Record they are registered to
listen for until the file has been completely read.
--------------------------------------------------------------------------
(the above has the package names converted to the Apache version. The
sourceforge version of the how-to still has the old package names)
If also includes a code excerpt from org.apache.poi.hssf.dev.EFHSSF
which is "over-commented" (line by line style play by play of what's
going on). This is probably the easiest way to learn.
The HOWTO should be included in the documentation archive. It will also
be up on the new website at jakarta very shortly. It seems to answer
both your questions.
The event model is based on the design of the AWT event model with some
ideas borrowed from SAX as well. The idea is you register for what
you're interested in. You'll have to learn a bit about Excel files to
use it and twist your mind just a bit. The idea is to read the file as
efficiently as possible. You essentially register to listen for the low
level structures in the file and your listener is called when one
occurs. Its pretty straightforward once you get used to it.
If you still do not understand provided the above, then please bear with
us. Try to use it based on the code in the *hssf.dev.EFHSSF class. Ask
specific questions on where you are stumped and I will attempt to answer
them as best as I can. From there I will improve the documentation and
you are encouraged to do so as well.
THanks,
Andy
On Fri, 2002-02-01 at 03:25, [EMAIL PROTECTED] wrote:
> Hello again,
>
> I'm afraid I can't seem to figure out any of this
> eventmodel stuff, as I can't seem to find this
> so-called HOWTO anywhere. What exactly are these
> record values that I would try to catch, and how does
> this differ from what I would be doing normally?
>
> My apologies if you already explained this, and I
> simply didn't understand it.
>
> Thanks,
> -Russell Stadler
>
> "Andrew C. Oliver" wrote
>
> > Message-Id:
> <[EMAIL PROTECTED]>
> > List-Help: <mailto:[EMAIL PROTECTED]>
> > List-Unsubscribe:
> <mailto:[EMAIL PROTECTED]>
> > From: "Andrew C. Oliver" <[EMAIL PROTECTED]>
> > X-Mailer: Evolution/1.0.0.99+cvs.2001.12.18.08.57
> (Preview Release)
> > Reply-To: [EMAIL PROTECTED]
> > Date: 30 Jan 2002 06:56:51 -0500
> > Received: (cpmta 17057 invoked from network); 30 Jan
> 2002 04:07:53 -0800
> > Received: from 192.18.49.131 (HELO
> nagoya.betaversion.org)
> > by smtp.c000.snv.cp.net (209.228.32.61) with SMTP;
> 30 Jan 2002 04:07:53 -0800
> > Received: (qmail 11059 invoked by uid 97); 30 Jan
> 2002 12:07:43 -0000
> > Received: (qmail 11031 invoked from network); 30 Jan
> 2002 12:07:42 -0000
> > Mailing-List: contact
> [EMAIL PROTECTED]; run by ezmlm
> > Content-Type: text/plain
> > X-Received: 30 Jan 2002 12:07:53 GMT
> > List-Post: <mailto:[EMAIL PROTECTED]>
> > Subject: Re: Help using POI
> > In-Reply-To:
> <[EMAIL PROTECTED]>
> > X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
> > References:
> <[EMAIL PROTECTED]>
> > List-Subscribe:
> <mailto:[EMAIL PROTECTED]>
> > Precedence: bulk
> > Delivered-To: [EMAIL PROTECTED]
> > Delivered-To: mailing list [EMAIL PROTECTED]
> > Return-Path:
> <[EMAIL PROTECTED]>
> > MIME-Version: 1.0
> > Content-Transfer-Encoding: 7bit
> > To: [EMAIL PROTECTED]
> >
> > On Wed, 2002-01-30 at 00:14, [EMAIL PROTECTED]
> wrote:
> > > Two things:
> > >
> > > First, when exactly are you planning on moving to
> > > Jakarta?
> > >
> >
> >
> > hummm...is now good? :-)
> >
> > [andy@linux2 jakarta-poi]$ . ~/.jakcvs
> > [andy@linux2 jakarta-poi]$ cvs -z3 import -m "initial
> import"
> > jakarta-poi jakarta-poi start
> > Warning: Remote host denied X11 forwarding.
> > I jakarta-poi/POILogger.log
> > I jakarta-poi/p1.log
> > I jakarta-poi/p2.log
> >
> >
> >
> > > Second, I don't really follow what you mean. What
> > > exactly is the new eventmodel API and how would I go
> > > about using it? What was I doing that took 80mb
> that
> > > now takes 7?
> > >
> >
> > Sorry. The event model which is in the development
> builds lets you
> > catch record values as they happen instead of
> building the whole model.
> >
> > I was just saying as an example something that takes
> like 80mb in the
> > usermodel (which you still have to use to write)
> would take like 7 in
> > the eventmodel.
> >
> > see net.sourceforge.poi.hssf.eventmodel
> >
> > I think there is info in the howto. its only in the
> development builds
> > though.
> >
> >
> > > -Russell Stadler
> > >
> > > "Andrew C. Oliver" wrote
> > >
> > >
> > > > In 1.2.0 there is an easier way to do this. If
> you
> > > use
> > > > the new eventmodel API you can just catch the
> cells
> > > and
> > > > ignore any that you're not interested.
> > > >
> > > > Just to give you an idea... What takes 80mb
> > > currently, takes
> > > > only 7mb with the eventmodel API.
> > > >
> > > > Once we move to jakarta, I'm going to push for an
> > > interim
> > > > release.
> > > >
> > > > -Andy
> > > >
> > > >
> > > > On Tue, 2002-01-29 at 03:15, [EMAIL PROTECTED]
> > > wrote:
> > > > > I didn't download 1.2.0, however when I removed
> the
> > > > > graphs, the problems disappeared.
> > > > >
> > > > > I think that solves pretty much all of my
> current
> > > > > problems, although I do have one more question.
> > > > >
> > > > > Is there any easy way to work with columns,
> instead
> > > of
> > > > > rows? For example, say I have a big sheet full
> of
> > > data
> > > > > (such as the one I uploaded as a problematic
> sample,
> > > > > less the graphs of course) and I wanted to
> write a
> > > > > program that would calculate the average of
> every
> > > > > single column, and add it to the bottom of the
> > > column.
> > > > > I would think that if this sheet were organized
> such
> > > > > that instead of having columns of data, it had
> > > rows, I
> > > > > could just go through a HSSFRow's cells, and
> average
> > > > > them. With a column, I need to access a
> different
> > > row
> > > > > every time I want to move down in the column.
> Is
> > > there
> > > > > an easier way to do this?
> > > > >
> > > > > Thanks again for all the help,
> > > > > Russell Stadler
> > > > >
> > > > > "Andrew C. Oliver" wrote
> > > > >
> > > > > >
> > > > > > Assigning Glen to look at this. The sample
> has
> > > > > embedded graphs.
> > > > > >
> > > > > > Tested with reasonably recent build and it
> still
> > > > > failed.
> > > > > >
> > > > > > Russell,
> > > > > >
> > > > > > POI::HSSF 1.0.2 will not handle embedded
> graphs,
> > > they
> > > > > are treated as
> > > > > > separate sheets within sheets and it has no
> idea
> > > what
> > > > > to do with them.
> > > > > > Glen has new code to handle graphs in the
> current
> > > > > development build.
> > > > > >
> > > > > > Download the latest development build and try
> them
> > > > > with it. I'll do so
> > > > > > shortly, but I don't have time to finish
> right now
> > > > > (meeting someone).
> > > > > >
> > > > > > If you remove the graphs it should work fine.
> > > > > Regardless this shouldn't
> > > > > > throw an exception (at the very least) in the
> > > latest
> > > > > development build.
> > > > > >
> > > > > > ccing glen.
> > > > > >
> > > > > > -Andy
> > > > > >
> > > > > > On Mon, 2002-01-28 at 12:12,
> [EMAIL PROTECTED]
> > > > > wrote:
> > > > > > > Hello again,
> > > > > > >
> > > > > > > My apologies for the inadequate
> information.
> > > The
> > > > > > > version of POI is 1.0.2. I thought it was
> all
> > > .xls
> > > > > > > files, however it turns out I am mistaken.
>
> > > had a
> > > > > > > number of sample files I was working with,
> which
> > > > > were
> > > > > > > all files that had been exported from
> Radview's
> > > > > WebLoad
> > > > > > > software. When I filled in a few cells
> > > manually in
> > > > >
> > > > > > > sheet, it worked fine.
> > > > > > >
> > > > > > > I've uploaded both the .xls I created, and
> one
> > > of
> > > > > the
> > > > > > > .xls files that failed
> http://www.qxfr.com/poi.
> > > The
> > > > > > > one that works is named ok.xls, the other is
> > > named
> > > > > > > problem.xls
> > > > > > >
> > > > > > > Based on what you've said, I think it's
> either
> > > 1 or
> > > > > 2.
> > > > > > > I can view the workbook in Excel (2000)
> fine,
> > > so I
> > > > > > > think that it's not a result of number 3.
> It
> > > could
> > > > > be
> > > > > > > a result of 4 or 5, but I'm doubtful,
> because
> > > it did
> > > > > > > work fine with the workbook I just filled a
> > > little
> > > > > with
> > > > > > > gibberish.
> > > > > > >
> > > > > > > I don't know how I would check if the XLS
> files
> > > are
> > > > > > > encrypted or not in proper format.
> > > Additionally, I
> > > > > > > would like to know if it is possible to
> > > unprotect a
> > > > > > > file, or convert it into proper excel
> format.
> > > > > > >
> > > > > > > If it's at all helpful, I uploaded the
> source
> > > to a
> > > > > > > little test program that reproduces this
> problem
> > > > > with
> > > > > > > the problem.xls file.
> > > > > > >
> > > > > > > Thanks for your help,
> > > > > > > Russell Stadler
> > > > > > >
> > > > > > >
> > > > > > > "Andrew C. Oliver" wrote
> > > > > > >
> > > > > > > >
> > > > > > > > What version of POI is this? 1.0.2 or
> 1.2.0.
> > > > > Please
> > > > > > > provide a
> > > > > > > > sample xls if possible. This is not
> really
> > > > > > > sufficient data?
> > > > > > > > Is it ONLY on this XLS or on all XLS?
> > > > > > > >
> > > > > > > > Here are some wild guesses
> > > > > > > >
> > > > > > > > 1. The sheet is "protected" (which is a
> > > > > Microsoftism
> > > > > > > for encrypted)
> > > > > > > > 2. The sheet is not in (proper) Excel 97
> > > format
> > > > > (For
> > > > > > > example StarOffice
> > > > > > > > 5.1 creates basically a cross-hybrid
> > > between 97
> > > > > > > and 95 format...which
> > > > > > > > Excel 97 can read but later versions of
> > > Excel
> > > > > > > officially cannot and
> > > > > > > > HSSF ONLY plans to support 97+)
> > > > > > > > 3. The Workbook is invalid
> > > > > > > > 4. you've stumbled upon something HSSF
> doesn't
> > > > > > > support (in which case a
> > > > > > > > sample would be REALLY appreciated)
> > > > > > > > 5. There is a bug in HSSF that you've
> > > uncovered
> > > > > (see
> > > > > > > #4).
> > > > > > > >
> > > > > > > > In any case a sample XLS or more
> information
> > > > > would be
> > > > > > > awesome!
> > > > > > > >
> > > > > > > > -Andy
> > > > > > > >
> > > > > > > > On Mon, 2002-01-28 at 00:02,
> > > [EMAIL PROTECTED]
> > > > > > > wrote:
> > > > > > > > > Hello,
> > > > > > > > >
> > > > > > > > > When executing the line
> > > > > > > > >
> > > > > > > > > HSSFWorkbook workbook = new
> > > HSSFWorkbook(poifs);
> > > > > > > > >
> > > > > > > > > with poifs being an existing
> POIFSFileSystem
> > > > > created
> > > > > > > > > from an inputstream, I recieve the
> following
> > > > > > > exception:
> > > > > > > > >
> > > > > > > > >
> > > > >
> ----------------------------------------------------
> > > > > > > > > java.lang.NullPointerException
> > > > > > > > >
> > > > > > > > > at
> > > > > > > > >
> > > > > > >
> > > > >
> > >
>
>net.sourceforge.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet(HSSFSheet.java:184)
> > > > > > > > >
> > > > > > > > > at
> > > > > > > > >
> > > > > > >
> > > > >
> > >
> net.sourceforge.poi.hssf.usermodel.HSSFSheet.<init>(HSSFSheet.java:142)
> > > > > > > > >
> > > > > > > > > at
> > > > > > > > >
> > > > > > >
> > > > >
> > >
> net.sourceforge.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:159)
> > > > > > > > >
> > > > >
> ----------------------------------------------------
> > > > > > > > >
> > > > > > > > > Any help would be greatly appreciated.
> > > > > > > > >
> > > > > > > > > -Russell Stadler
> > > > > > > > --
> > > > > > > > www.superlinksoftware.com
> > > > > > > > www.sourceforge.net/projects/poi - port of
> > > Excel
> > > > > > > format to java
> > > > > > > >
> > > > > > >
> > > > >
> > >
> http://developer.java.sun.com/developer/bugParade/bugs/4487555.html
> > > > > > > > - fix java generics!
> > > > > > > >
> > > > > > > >
> > > > > > > > The avalanche has already started. It is
> too
> > > late
> > > > > for
> > > > > > > the pebbles to
> > > > > > > > vote.
> > > > > > > > -Ambassador Kosh
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > ------------------------------------------
> > > > > > > [EMAIL PROTECTED]
> > > > > > --
> > > > > > www.superlinksoftware.com
> > > > > > www.sourceforge.net/projects/poi - port of
> Excel
> > > > > format to java
> > > > > >
> > > > >
> > >
> http://developer.java.sun.com/developer/bugParade/bugs/4487555.html
> > > > > > - fix java generics!
> > > > > >
> > > > > >
> > > > > > The avalanche has already started. It is too
> late
> > > for
> > > > > the pebbles to
> > > > > > vote.
> > > > > > -Ambassador Kosh
> > > > >
> > > > >
> > > > >
> > > > > ------------------------------------------
> > > > > [EMAIL PROTECTED]
> > > > --
> > > > www.superlinksoftware.com
> > > > www.sourceforge.net/projects/poi - port of Excel
> > > format to java
> > > >
> > >
> http://developer.java.sun.com/developer/bugParade/bugs/4487555.html
> > > > - fix java generics!
> > > >
> > > >
> > > > The avalanche has already started. It is too late
> for
> > > the pebbles to
> > > > vote.
> > > > -Ambassador Kosh
> > --
> > www.superlinksoftware.com
> > www.sourceforge.net/projects/poi - port of Excel
> format to java
> >
> http://developer.java.sun.com/developer/bugParade/bugs/4487555.html
> > - fix java generics!
> >
> >
> > The avalanche has already started. It is too late for
> the pebbles to
> > vote.
> > -Ambassador Kosh
>
>
>
> ------------------------------------------
> [EMAIL PROTECTED]
--
www.superlinksoftware.com
www.sourceforge.net/projects/poi - port of Excel format to java
http://developer.java.sun.com/developer/bugParade/bugs/4487555.html
- fix java generics!
The avalanche has already started. It is too late for the pebbles to
vote.
-Ambassador Kosh