poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bigwood, David" <dbigw...@metatomix.com>
Subject RE: HSSFRow.cellIterator order
Date Thu, 25 Mar 2004 15:29:32 GMT
I think all you have to be careful of is that row.getLastCellNum() returns
one more than the actual largest index. Then loo accordingly being careful to
handle null cell objects (blank cells) within the range. See a code snippet
below:

	private void processRow(HSSFRow row) {
		int firstCellNum = row.getFirstCellNum();
		int lastCellNum = row.getLastCellNum();
		int rowNum = row.getRowNum();
		if( debug ) System.out.println("\tProcessing row [" 
			+ rowNum
			+ "] from cell ["
			+ firstCellNum
			+ "] to ["
			+ lastCellNum
			+ "]");
		for( int i = firstCellNum; i < lastCellNum; i++ ) {
			HSSFCell cell = row.getCell((short) i);
			if( cell != null ) {
				processCell(cell);		
			} else {
				processSpacerCell(i);
			}
		}
	}

My mini0-project is to generate generic XML from any spreadsheet, so the
processCell(cell) and processSpacerCell(cell) methods just output the
necessary XML to the buffer.

Hope this is useful.
-DAB



> -----Original Message-----
> From: Patrick Lightbody [mailto:Patrick.Lightbody@spokesoftware.com] 
> Sent: Thursday, March 25, 2004 10:20 AM
> To: POI Users List
> Subject: RE: HSSFRow.cellIterator order
> 
> 
> But traversing by column still gives you a column number that 
> when passed to getCell(short) may result in an 
> ArrayIndexOutOfBounds. Are you not experiencing this problem?
> 
> > -----Original Message-----
> > From: Karl-Heinz Zengerle [mailto:karl-heinz.zengerle@sawag.com]
> > Sent: Thursday, March 25, 2004 6:40 AM
> > To: 'POI Users List'
> > Subject: AW: HSSFRow.cellIterator order
> > 
> > Hi Patrick.
> > I think it's not useless. It's just not an optimum efficiency
> > (traversing via column numbers instead of the iterator and 
> ignoring null
> > cells). It's not invented by POI. All what they do is based 
> on Microsoft
> > behaviour.
> > Regards,	Karl-Heinz.
> > 
> > 
> > -----Ursprüngliche Nachricht-----
> > Von: Patrick Lightbody [mailto:Patrick.Lightbody@spokesoftware.com]
> > Gesendet: Donnerstag, 25. März 2004 15:26
> > An: POI Users List
> > Betreff: RE: HSSFRow.cellIterator order
> > 
> > That's a bummer -- seems to make POI almost completely useless for
> > simple scanning of rows. Are there _any_ workarounds short 
> of catching
> > AIOOBE? Seems like a pretty nasty problem
> > 
> > > -----Original Message-----
> > > From: Karl-Heinz Zengerle [mailto:karl-heinz.zengerle@sawag.com]
> > > Sent: Thursday, March 25, 2004 6:07 AM
> > > To: 'POI Users List'
> > > Subject: AW: HSSFRow.cellIterator order
> > >
> > > Hi Patrick.
> > > You see exactly the similarity of the questions which 
> I've also seen.
> > In
> > > that thread several reasons for that behaviour were mentioned.
> > > Regards,	Karl-Heinz.
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Patrick Lightbody 
> [mailto:Patrick.Lightbody@spokesoftware.com]
> > > Gesendet: Donnerstag, 25. März 2004 15:03
> > > An: POI Users List
> > > Betreff: RE: HSSFRow.cellIterator order
> > >
> > > Karl,
> > > Thanks for the heads up -- I hadn't been following the 
> thread but I'll
> > > take a look. I'm guessing also related to this is the 
> fact that even
> > > though the internal cells ArrayList is size 1, getLastCellNumber()
> > > returns something larger, which causes problems even if I 
> access by
> > > column number. I end up having to catch AIOOBE :(
> > >
> > > Patrick
> > >
> > > > -----Original Message-----
> > > > From: Karl-Heinz Zengerle [mailto:karl-heinz.zengerle@sawag.com]
> > > > Sent: Thursday, March 25, 2004 5:48 AM
> > > > To: 'POI Users List'
> > > > Subject: AW: HSSFRow.cellIterator order
> > > >
> > > > Hi Patrick.
> > > > I posted the topic "phantom cells ...?" recently. For 
> me it looks
> > like
> > > > that the iterator traverses in the internal order. If 
> you don't use
> > > the
> > > > iterator
> > > > But access the column by its number within the row you 
> surely have
> > the
> > > > desired effect.
> > > > Look at the last mails belonging to the topic above. I 
> think there
> > > > exactly your problem is also mentioned.
> > > > Regards,	Karl-Heinz.
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Patrick Lightbody 
> [mailto:Patrick.Lightbody@spokesoftware.com]
> > > > Gesendet: Donnerstag, 25. März 2004 14:36
> > > > An: poi-user@jakarta.apache.org
> > > > Betreff: HSSFRow.cellIterator order
> > > >
> > > > I seem to be getting the order of my cell iterator in 
> something that
> > > is
> > > > different from the right-to-left order as defined in my 
> spreadsheet.
> > > Why
> > > > is that?
> > > >
> > > > Patrick
> > > >
> > > >
> > > >
> > > >
> > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: 
> poi-user-help@jakarta.apache.org
> > >
> > >
> > > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> > >
> > >
> > > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
> 
> 

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


Mime
View raw message