You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Davis, Zach" <Za...@polk.com> on 2008/12/22 15:41:33 UTC

Issues with Sheet.getLastRowNum() and getPhysicalNumberOfRows() being incorrect.

I have an Excel document with 18 rows. 18th row being the row with 18
displayed in Excel. I would expect Sheet.getLastRowNum() to return 17
like it does for my other 16,000 files. For some reason I'm getting 19.

So this isnt the actual code but rather a simplification that details my
problem.


....  (omitted sheet getting loaded from disk)

int firstRowNum = sheet.getFirstRowNum();
int lastRowNum = sheet.getLastRowNum();

System.out.println("Last row: " + sheet.getLastRowNum());
System.out.println("Phys row: " + sheet.getPhysicalNumberOfRows());

for (int i = firstRowNum; i <= lastRowNum; i++) {
	row = sheet.getRow(i);
	if (row == null) {
	    System.err.println("ReadCells(): Row " + i + " was null!");
	    System.exit(2);
	}
	...... (more code)
}

Produces:

Last row: 19
Phys row: 19
ReadCells(): Row 18 was null!

Now I would expect the valid number of rows to be from 0-17 and using
excel my last row does appear to be at 18 in the UI. I'm using poi 3.1
FINAL and I've already checked the changelogs to see if this bug was
fixed in newer versions. Since this is part of a large project I am
unable to upgrade poi but using the latest version my test code still
bombs.

I'm interested in any workarounds or suggestions. Due to these files
containing personal information I am not authorized to provide them
unfortunately :(.

Cheers,
Zach Davis
Associate IT Programmer Analyst
R.L. Polk Southfield Office

*****************************************************************
This message has originated from R. L. Polk & Co.,
26955 Northwestern Highway, Southfield, MI 48033.
R. L. Polk & Co. sends various types of email
communications.  If this email message concerns the
potential licensing of a Polk product or service, and
you do not wish to receive further emails regarding Polk
products, forward this email to Do_Not_Send@polk.com
with the word "remove" in the subject line.

The email and any files transmitted with it are confidential
and intended solely for the individual or entity to whom they
are addressed.

If you have received this email in error, please delete this
message and notify the Polk System Administrator at
postmaster@polk.com.
*****************************************************************

Re: Issues with Sheet.getLastRowNum() and getPhysicalNumberOfRows() being incorrect.

Posted by Pierre Lavignotte <pi...@gmail.com>.
Oups, sorry but no idea for this one ;)

Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com


On Mon, Dec 22, 2008 at 4:58 PM, Davis, Zach <Za...@polk.com> wrote:

> So your assumption was correct and by simply ignoring the error I found a
> new row at index 19. Odd behavior but my data is there and readable so I'm
> happy.
>
> I do get some odd errors on a couple other files though. By just trying to
> load the workbook I get the below message. Any ideas?
>
>        Cannot remove block[ 252 ]; out of range[ 0 - 224 ]
>
> Cheers,
> Zach Davis
> Associate IT Programmer Analyst
> R.L. Polk Southfield Office
>
>
> -----Original Message-----
> From: Pierre Lavignotte [mailto:pierre.lavignotte@gmail.com]
> Sent: Monday, December 22, 2008 10:05 AM
> To: POI Users List
> Subject: Re: Issues with Sheet.getLastRowNum() and
> getPhysicalNumberOfRows() being incorrect.
>
> Hi,
>
> the only thing I think about is that you may have one or two blank rows
> (=no
> record) before the 18th, and one or two rows after the 18th with empty data
> so they doen't display in Excel.
> Hope I'm clear...
>
> Try :
> for (int i = firstRowNum; i <= lastRowNum; i++) {
>       row = sheet.getRow(i);
>       System.out.println("Row " + i);
> }
>
> Maybe you'll find there is a missing number in the 0-17 range, and a row at
> index 19.
>
> Good luck,
> Pierre
>
> Cordialement,
> Pierre Lavignotte
> Ingénieur Conception & Développement
> http://pierre.lavignotte.googlepages.com
>
>
> On Mon, Dec 22, 2008 at 3:41 PM, Davis, Zach <Za...@polk.com> wrote:
>
> > I have an Excel document with 18 rows. 18th row being the row with 18
> > displayed in Excel. I would expect Sheet.getLastRowNum() to return 17
> > like it does for my other 16,000 files. For some reason I'm getting 19.
> >
> > So this isnt the actual code but rather a simplification that details my
> > problem.
> >
> >
> > ....  (omitted sheet getting loaded from disk)
> >
> > int firstRowNum = sheet.getFirstRowNum();
> > int lastRowNum = sheet.getLastRowNum();
> >
> > System.out.println("Last row: " + sheet.getLastRowNum());
> > System.out.println("Phys row: " + sheet.getPhysicalNumberOfRows());
> >
> > for (int i = firstRowNum; i <= lastRowNum; i++) {
> >        row = sheet.getRow(i);
> >        if (row == null) {
> >            System.err.println("ReadCells(): Row " + i + " was null!");
> >            System.exit(2);
> >        }
> >        ...... (more code)
> > }
> >
> > Produces:
> >
> > Last row: 19
> > Phys row: 19
> > ReadCells(): Row 18 was null!
> >
> > Now I would expect the valid number of rows to be from 0-17 and using
> > excel my last row does appear to be at 18 in the UI. I'm using poi 3.1
> > FINAL and I've already checked the changelogs to see if this bug was
> > fixed in newer versions. Since this is part of a large project I am
> > unable to upgrade poi but using the latest version my test code still
> > bombs.
> >
> > I'm interested in any workarounds or suggestions. Due to these files
> > containing personal information I am not authorized to provide them
> > unfortunately :(.
> >
> > Cheers,
> > Zach Davis
> > Associate IT Programmer Analyst
> > R.L. Polk Southfield Office
> >
> > *****************************************************************
> > This message has originated from R. L. Polk & Co.,
> > 26955 Northwestern Highway, Southfield, MI 48033.
> > R. L. Polk & Co. sends various types of email
> > communications.  If this email message concerns the
> > potential licensing of a Polk product or service, and
> > you do not wish to receive further emails regarding Polk
> > products, forward this email to Do_Not_Send@polk.com
> > with the word "remove" in the subject line.
> >
> > The email and any files transmitted with it are confidential
> > and intended solely for the individual or entity to whom they
> > are addressed.
> >
> > If you have received this email in error, please delete this
> > message and notify the Polk System Administrator at
> > postmaster@polk.com.
> > *****************************************************************
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

RE: Issues with Sheet.getLastRowNum() and getPhysicalNumberOfRows() being incorrect.

Posted by "Davis, Zach" <Za...@polk.com>.
So your assumption was correct and by simply ignoring the error I found a new row at index 19. Odd behavior but my data is there and readable so I'm happy.

I do get some odd errors on a couple other files though. By just trying to load the workbook I get the below message. Any ideas?

	Cannot remove block[ 252 ]; out of range[ 0 - 224 ]

Cheers,
Zach Davis
Associate IT Programmer Analyst
R.L. Polk Southfield Office


-----Original Message-----
From: Pierre Lavignotte [mailto:pierre.lavignotte@gmail.com] 
Sent: Monday, December 22, 2008 10:05 AM
To: POI Users List
Subject: Re: Issues with Sheet.getLastRowNum() and getPhysicalNumberOfRows() being incorrect.

Hi,

the only thing I think about is that you may have one or two blank rows (=no
record) before the 18th, and one or two rows after the 18th with empty data
so they doen't display in Excel.
Hope I'm clear...

Try :
for (int i = firstRowNum; i <= lastRowNum; i++) {
       row = sheet.getRow(i);
       System.out.println("Row " + i);
}

Maybe you'll find there is a missing number in the 0-17 range, and a row at
index 19.

Good luck,
Pierre

Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com


On Mon, Dec 22, 2008 at 3:41 PM, Davis, Zach <Za...@polk.com> wrote:

> I have an Excel document with 18 rows. 18th row being the row with 18
> displayed in Excel. I would expect Sheet.getLastRowNum() to return 17
> like it does for my other 16,000 files. For some reason I'm getting 19.
>
> So this isnt the actual code but rather a simplification that details my
> problem.
>
>
> ....  (omitted sheet getting loaded from disk)
>
> int firstRowNum = sheet.getFirstRowNum();
> int lastRowNum = sheet.getLastRowNum();
>
> System.out.println("Last row: " + sheet.getLastRowNum());
> System.out.println("Phys row: " + sheet.getPhysicalNumberOfRows());
>
> for (int i = firstRowNum; i <= lastRowNum; i++) {
>        row = sheet.getRow(i);
>        if (row == null) {
>            System.err.println("ReadCells(): Row " + i + " was null!");
>            System.exit(2);
>        }
>        ...... (more code)
> }
>
> Produces:
>
> Last row: 19
> Phys row: 19
> ReadCells(): Row 18 was null!
>
> Now I would expect the valid number of rows to be from 0-17 and using
> excel my last row does appear to be at 18 in the UI. I'm using poi 3.1
> FINAL and I've already checked the changelogs to see if this bug was
> fixed in newer versions. Since this is part of a large project I am
> unable to upgrade poi but using the latest version my test code still
> bombs.
>
> I'm interested in any workarounds or suggestions. Due to these files
> containing personal information I am not authorized to provide them
> unfortunately :(.
>
> Cheers,
> Zach Davis
> Associate IT Programmer Analyst
> R.L. Polk Southfield Office
>
> *****************************************************************
> This message has originated from R. L. Polk & Co.,
> 26955 Northwestern Highway, Southfield, MI 48033.
> R. L. Polk & Co. sends various types of email
> communications.  If this email message concerns the
> potential licensing of a Polk product or service, and
> you do not wish to receive further emails regarding Polk
> products, forward this email to Do_Not_Send@polk.com
> with the word "remove" in the subject line.
>
> The email and any files transmitted with it are confidential
> and intended solely for the individual or entity to whom they
> are addressed.
>
> If you have received this email in error, please delete this
> message and notify the Polk System Administrator at
> postmaster@polk.com.
> *****************************************************************
>

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


Re: Issues with Sheet.getLastRowNum() and getPhysicalNumberOfRows() being incorrect.

Posted by Pierre Lavignotte <pi...@gmail.com>.
Hi,

the only thing I think about is that you may have one or two blank rows (=no
record) before the 18th, and one or two rows after the 18th with empty data
so they doen't display in Excel.
Hope I'm clear...

Try :
for (int i = firstRowNum; i <= lastRowNum; i++) {
       row = sheet.getRow(i);
       System.out.println("Row " + i);
}

Maybe you'll find there is a missing number in the 0-17 range, and a row at
index 19.

Good luck,
Pierre

Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com


On Mon, Dec 22, 2008 at 3:41 PM, Davis, Zach <Za...@polk.com> wrote:

> I have an Excel document with 18 rows. 18th row being the row with 18
> displayed in Excel. I would expect Sheet.getLastRowNum() to return 17
> like it does for my other 16,000 files. For some reason I'm getting 19.
>
> So this isnt the actual code but rather a simplification that details my
> problem.
>
>
> ....  (omitted sheet getting loaded from disk)
>
> int firstRowNum = sheet.getFirstRowNum();
> int lastRowNum = sheet.getLastRowNum();
>
> System.out.println("Last row: " + sheet.getLastRowNum());
> System.out.println("Phys row: " + sheet.getPhysicalNumberOfRows());
>
> for (int i = firstRowNum; i <= lastRowNum; i++) {
>        row = sheet.getRow(i);
>        if (row == null) {
>            System.err.println("ReadCells(): Row " + i + " was null!");
>            System.exit(2);
>        }
>        ...... (more code)
> }
>
> Produces:
>
> Last row: 19
> Phys row: 19
> ReadCells(): Row 18 was null!
>
> Now I would expect the valid number of rows to be from 0-17 and using
> excel my last row does appear to be at 18 in the UI. I'm using poi 3.1
> FINAL and I've already checked the changelogs to see if this bug was
> fixed in newer versions. Since this is part of a large project I am
> unable to upgrade poi but using the latest version my test code still
> bombs.
>
> I'm interested in any workarounds or suggestions. Due to these files
> containing personal information I am not authorized to provide them
> unfortunately :(.
>
> Cheers,
> Zach Davis
> Associate IT Programmer Analyst
> R.L. Polk Southfield Office
>
> *****************************************************************
> This message has originated from R. L. Polk & Co.,
> 26955 Northwestern Highway, Southfield, MI 48033.
> R. L. Polk & Co. sends various types of email
> communications.  If this email message concerns the
> potential licensing of a Polk product or service, and
> you do not wish to receive further emails regarding Polk
> products, forward this email to Do_Not_Send@polk.com
> with the word "remove" in the subject line.
>
> The email and any files transmitted with it are confidential
> and intended solely for the individual or entity to whom they
> are addressed.
>
> If you have received this email in error, please delete this
> message and notify the Polk System Administrator at
> postmaster@polk.com.
> *****************************************************************
>