We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Cells - how to get the last cell on worksheet in the way that MS Excel Interop does?

Hi,
We need to create a named range in worksheet and for that we used the following MS Excel Interop:
Cells.SpecialCells(XlCellType.xlCellTypeLastCell) to get the very last cell on the sheet. Note that it takes into account max column and return cell in that column even if cell on the last row is empty for that column. Since we needed the whole data range it served our purpose well.

Now, translating our code to Aspose.Cells we tried to use Cells.LastCell. But that gives last populated cell on the last row. So if that row has no data for the last column it won’t give it as the last cell.
Here is example to clarify.
A B C
1 a1 b1 c1
2 a2

MS Excel InteropCells.SpecialCells(XlCellType.xlCellTypeLastCell) = "C2"
Aspose.Cells’ Cells.LastCell = “A2”.
Is there an easy way to get “C2” in Aspose.Cells ? Of course, we can iterate through each column to find out maximum and then get last cell using it, but we are looking for easier way





This message was posted using Page2Forum from LastCell Property - Aspose.Words for .NET

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I will move your request to the Aspose.Cells forum and my colleagues will answer you shortly.

Best regards,

Hi,

I think you may try the following code to get your desired cell.
Sample code:

Workbook wb = new Workbook(“e:\test\Book1.xlsx”);
Worksheet ws = wb.Worksheets[0];
int maxdatacol = ws.Cells.MaxDataColumn;
int maxdatarow = ws.Cells.MaxDataRow;

String cellname = CellsHelper.CellIndexToName(maxdatarow, maxdatacol);
MessageBox.Show(cellname);


Thank you.

Thanks, Amjad!