Free Support Forum - aspose.com

Columns.Count property is always 0

Hi,

For the attached file
Sheet.Cells.Columns.Count is always 0.

Can you please help me with that?
As I have 3 columns in the file.
But still somehow I can read my data.

I tried with latest dll for Aspose.Cells.

Thanks

(And sorry for fake name for my account)

Hi,

Thanks for your posting and using Aspose.Cells.

Please use Sheet.Cells.MaxColumn property instead,. It will give you correct column count.

But I need enumerator/Collection for Columns.

And funny thing is Sheet.Cells.Columns.Count works for some files.

Another question is that does MaxDataRow property works fine?

And last question what should I do to remove trailing empty rows?

DeleteBlankRows() does not delete trailing rows. (I guess it loops through MaxDataRow not MaxRow)

Do you have any known issues with that?

Thank
Dhirendra

Hi,

Well, you slightly misunderstood the Cells.Columns.Count attribute. The property would give you columns count but, the columns with standard (default) settings / formatting are not included to be counted. For your information, the Rows.Count and Columns.Count are mainly useful if you want to retrieve the number of rows / columns which are initialized / used in a worksheet and also those rows / columns other than with the default formatting/setting in a worksheet.

Please always use Cells.MaxDataColumn / Cells.MaxDataRow and Cells.MaxColumn/Cells.MaxRow attributes to get the farthest column and row indexes. So, you should change your sample code accordingly.

For:
"And last question what should I do to remove trailing empty rows?

DeleteBlankRows () does not delete trailing rows. (I guess it loops through MaxDataRow not MaxRow) "

Well, there is no data after row 10, it does not make any difference. Also, even if you delete rows (after 10th row) in MS Excel manually, it will always fill rows to make the total/count to 1048576.
Kindly let us know if you still need some clarifications or other confusion, we would be happy to help you.

Hi
Sorry To say but, if I keep pressing enter after the last row MaxRow get increased for me.

If I have data in row 10(index 10) and i press enter 3 times it increases MaxRow to 13.

Thanks

Hi,


Well, it works fine. See the sample code below with comments.

Sample code:

//Note: I simply open your file and click on A11 cell, now press enter three times and then resave the file.
Workbook wb = new Aspose.Cells.Workbook(“e:\test2\iMPeX.xlsx”);
// Get the Maximum row which contains data in the sheet
int maxdataRow = wb.Worksheets[0].Cells.MaxDataRow; //9 OK
// Get the Maximim row which have either formatting or data etc. in the sheet
int maxRow = wb.Worksheets[0].Cells.MaxRow; //9 OK

And, please use/try our latest fix/version of the product: Aspose.Cells for .NET (Latest Version)

Hi
You are Right, My Bad.
But when I add border and use DeleteBlankRows()

It does not delete trailing empty rows.

Please See the attachments.(Values for MaxRow and MaxDataRow)

Thanks

Hi,


Yes, sure it won’t delete any row if at least one cell (of the row) contains any type of formatting (borders for your case).

Thanks for your understanding!

Thanks

But that doesn’t help developers.

Doesn’t matter where is the blank row DeleteBlankRows should delete all the blank rows(Keeping in mind the formatting)

Then Why It Deletes Cells From middle of the table.
I have Border over there too.

It makes no sense.

Please Reply Soon…

Hi,


Please try out our latest fix/version of the product: Aspose.Cells for .NET (Latest Version)
It works according to your needs.

See the sample code with comments and with the attached input Excel file. I have also attached the output Excel file here for your reference.

Sample code:

//Note: I simply open your file, select the data including extra two rows (11 and 12) and then apply borders round it and resave the file.
Workbook wb = new Aspose.Cells.Workbook(“e:\test2\iMPeX.xlsx”);
// Get the Maximum row which contains data in the sheet
int maxdataRow = wb.Worksheets[0].Cells.MaxDataRow;
// Get the Maximim row which have either formatting or data etc. in the sheet
int maxRow = wb.Worksheets[0].Cells.MaxRow;

//Delete the blank rows (whether they have some sort of formatting).
wb.Worksheets[0].Cells.DeleteBlankRows(); // Now the row 11 and 12 are also removed as per your needs.

wb.Save(“e:\test2\outimpeX.xlsx”);

Thank you.