poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MSB <markbrd...@tiscali.co.uk>
Subject Re: how to compare two excel file with apache poi
Date Wed, 07 Jul 2010 06:39:42 GMT

Sorry, I am not too sure what you are asking for here. Are you asking how to
discover how many rows there are on a worksheet - and how many cells there
are on a row as well? If so, the answer can be quite complex because what
you see as an empty row or cell when you view the workbook using Excel may
not actually be so. Excel will create a record for the row/cell if it
believe that anything has been done to warrant that - for example, if the
user populated a cell in error and then removed the contents, it is likely
that Excel will still create records for the row and cell even if you do not
actually see it on the worksheet. POI will read and report this row and that
may be why the count of rows you are seeing differs.

The two methods - getPhysicalNumberOfRows() and getLastRowNum() are designed
to perform completely different functions and will return different values.
The first - getPhysicalNumberOfRows() - will return a number that indicates
how many rows on the worksheet have been populated with data; more
accurately, how many row records exist. Imagine, therefore, that you have a
worksheet where only rows 10, 11 and 12 are populated, this method will
simply return the number 3. The getLastRowNum() method on the other hand
will return the index number of the bottom most row - in the case above, row
number 12 - poi index 11.


Mark B

mnsmcn wrote:
> Joined: Apr 19, 2008
> Posts: 48 
>  posted Today 10:30:06 AM    
> hi all 
> i have a task to compare excel sheets,that should be generic,so that at
> run time it can be any excel file. 
> i have written a code which checks rows and cells based on which i have
> written a logic to check one row with other row ie cells in it also. 
> if they are differnt ,then color with blue in both cells and in both file. 
> if they are same ,color it with common color and in both file
> but my problem is if sheet contain empty rows it is not giving proper
> count ie  used getPhysicalNumberOfRows(),pSheet.getLastRowNum() which is
> not counting empty row. 
> similarly cell if there is a row with cells ie last two cells of a row are
> empty its showing 1 less count i used both methods but not getting proper
> cell count ie 
> .getLastCellNum(),getPhysicalNumberOfCells(). 
> please give me idea for proper row count and cells,where my logic depends
> on it. 
> or code snippets to compare to excel sheets. 
> please give your inputs regarding the above. 

View this message in context: http://old.nabble.com/how-to-compare-two-excel-file-with-apache-poi-tp29092827p29093114.html
Sent from the POI - Dev mailing list archive at Nabble.com.

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

View raw message