Free Support Forum - aspose.com

Get Last Cell address in a row

Dear Sir,

We are in a process of converting Interop.Excel to Aspose.Cells . Request your help on how to find Last Cell address with data in a given row using Aspose.Cell. We are using Aspose.Cells 7.3.3.0 for .NET

Following is the old code using Interop. Requires the corresponding alternative in Aspose. Also is there any tools available to convert the code in Excel.Interop to Aspose.Cells or any good documentation on this.

strStartTsLoc = WorkSheet1.Range("D3").Next(2, 0).Address(False, False)
strStartTsEndLoc = WorkSheet1.Range(strStartTsLoc).End(XlDirection.xlToRight).Address(False, False)

Here D3 is temporarily hardcoded for better understanding actually this will be dynamic

Thanks
Anish

Hi,


Please try Row.LastDataCell for your requirements. This API is recently added and is used to get the last cell having data in it in a given row. Once you found the cell then you may use Cell.Row and Cell.Column attributes to get the address of that cell.

Thank you.

Thanks for the quick reply.

Can you please suggest an alternative to the highlighted one below

WorkSheet1.Range("D3").Next(2, 0).Address(False, False)

Anish

Hi,


Well, I am not sure about Next().Address attribute, but I think if you need to get the next cell at some offset with respect to the current cell, you may add your desired numeric offset to cell.Row and cell.Column properties.
e.g

int row = cell.Row + 2;
int col = cell.Column;


Thank you.