Free Support Forum - aspose.com

Cells behavior

Hello,

We are using Aspose.Cells and it works very well but I would like to understand the behavior of the Cells collection.
Range of the existing cell in a worksheet seems to be defined by the MaxRow and MaxColumn property of the Cells objet. If you use the CheckExistence in a cell inside this range it return to you the index of the Cell in the Cells collection. Everything fine here.

Now let me show you a behavior that I found inconsistent, you have a worksheet with MaxRow = 5 and MaxColumn = 8, if you access a cell out of the range defined by the properties MaxRow and MaxColumn using book.Worksheets[0].Cells[9999, 9999] (example) you can see that MaxRow and MaxColumn properties have been extended to 9999 and 9999. You don’t get an IndexOutOfRange exception or anything like that you could suppose to get, the cell contain a Aspose.Cell objet (type IsNull). If you use the CheckExistence on this cell, it returns -1.
Can you tell me how this works or give me a link on a documentation that can precisely explain it to me ?
Which critera is used by the CheckExistence method to define that a Cell doesn’t exists ?
Please tell me if I missed something in the understanding of Aspose.Cells.

Best regards,
Cédric

Hi,

Thanks for considering Aspose.

Well, when you access a cell in a worksheet, the cell would be initialzed and may affect the MaxRow / MaxColumn value. I think you should use MaxDataRow / MaxDataColumn properties for your need.

Notes:

MaxRow / MaxColumn returns the maximum row/column cell's index value in a worksheet which is either initialized or having data / style.
MaxDataRow / MaxDataColumn returns the maximun row/column cell's index value in the worksheet which contain data.

Following is my sample code and I try to explain it more:

Sample code (I use a workbook .xlsx file, which contains data into its first worksheet, it contains data in the matrix 6*9=54 (maxrow / maxdatarow = 5, maxcolumn / maxdatacolumn = 9)):

Workbook workbook = new Workbook();
workbook.Open("d:\\test\\MyBook.xlsx",FileFormatType.Excel2007Xlsx);
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
MessageBox.Show(cells.MaxRow.ToString());//return 5 OK!
MessageBox.Show(cells.MaxColumn.ToString());//return 8 OK!
MessageBox.Show(cells.CheckExistence(9999,9999).ToString());
Cell cell = cells[9999,9999];//return -1 OK!
MessageBox.Show(cells.MaxDataRow.ToString());//return 5 but if you use MaxRow the value would be 9999.
MessageBox.Show(cells.MaxDataColumn.ToString());return 8 but if you use MaxColumn the value would be 9999.
MessageBox.Show(cells.CheckExistence(9999,9999).ToString()); return cell index number.

Thank you.

Hi,

Thanks for your answer. You explanation and your sample is nice but
I don’t have the same result on the last CheckExistence call, it returns -1 anyway.
Is it because I use Aspose.Cells version 4.4.0.0 ? Or is it something else ?

Can we download directly the lastest version of the binaries ? I found only a link to download an installer (*.msi). It would be nice to be able to download only the binaries.

Best regards,
Cédric

Please check this attached zip file. It includes the dll and template file. Please test them with code provided by Amjad.

It works with the new dll version as expected. Also tested with the xlsx and xls file I created.

Thanks you.