2 Replies Last post: Aug 18, 2008 11:08 AM by Heinrich Wendel  
Heinrich Wendel   7 posts since
Aug 14, 2008
Currently Being Moderated

Aug 14, 2008 11:35 AM

Get Last Row in Excel Workbook

Hi,

 

Is there a way to get the number of the last row in an Excel Workbook?

 

regards,

Heinrich Wendel

Mike McMaster   61 posts since
Aug 24, 2007
Currently Being Moderated
1. Aug 14, 2008 7:00 PM in response to: Heinrich Wendel
Re: Get Last Row in Excel Workbook

Hello Heinrich,

 

Take a look at Worksheet.getUsedRange(). This returns a Range object which contains all the cells in use. To get the last row, I imagine you'll need to do something like this:

 

List usedCells = worksheet.getUsedRange().getCells();

Cell lastCell = (Cell) usedCells.get(usedCells.size() - 1); // lastCell represents the bottom-right-most cell

int lastRow = lastCell.getRow();

 

-Mike

More Like This

  • Retrieving data ...