Free Support Forum - aspose.com

Row Count > 0- Column Count = 0?

I open an Excel spreadsheet via the Open() method. When I query Cells.Rows.Count, it returns 6 (what I am expecting).

When I query Cells.Rows.Columns.Count, I get 0.

How can a sheet have rows with no columns? If this is not the correct way to get the columns, let me know what I should be doing … I would like to iterate over the columns.

Thanks!

Hi,

Thanks for considering Aspose.

If any one wants to determine:

Following is the code with some comments. If any one wants to determine:

last row index which contains data / formattings, last column index which contains data / formattings, countings of cols / rows filled with data / styles other than those rows / cols with standard settings, total no. of cells filled with data/ styles in a worksheet. Kindly check the template file attached and then utilize the code for better understanding:

Workbook wb = new Workbook();
wb.Open("d:\\test\\tstbk1.xls");
Worksheet ws = wb.Worksheets[0];
int colcount = ws.Cells.Columns.Count;
int rowcount = ws.Cells.Rows.Count;
int maxcol = ws.Cells.MaxColumn;
int maxdatacol = ws.Cells.MaxDataColumn;
int maxdatarowincol = ws.Cells.MaxDataRowInColumn(3);
int maxrow = ws.Cells.MaxRow;
int maxdatarow = ws.Cells.MaxDataRow;
int noofcells = ws.Cells.Count;

MessageBox.Show("Cols count: " + colcount.ToString()); // Returns 8 ok... since the columns with standard (default) settings / formatting are not included.
MessageBox.Show("Rows count: " + rowcount.ToString()); // Returns 13 ok... since all the rows with default settings / formattings are not included in the collection.
MessageBox.Show("Max Column index which contains data / style attribute: " + maxcol.ToString()); // Returns 10 ok... since maximum data/styled column is K and its index is 10.
MessageBox.Show("Max Column index which contains data only: " + maxdatacol.ToString()); // // Returns 10 ok... since maximum data column is also K and its index is 10.
MessageBox.Show("Max row index which contains data in the fourth (D) column: " + maxdatarowincol.ToString()); // Returns 10 ok...since in the D column the data is filled up to 11th row and row index is 10.
MessageBox.Show("Max Row index which contains data / style attribute:" + maxrow.ToString());// Returns 23 ok... since the data / style is filled up to the 24th rows only so the last row index is 23.
MessageBox.Show("Max Row index which contains data only" + maxdatarow.ToString()); // Returns 23 ok... since the data is filled up to the 24th rows only so the last row index is 23.
MessageBox.Show("Total no. of cells: " + noofcells.ToString()); // Returns 87, since there are total 87 cells filled with data / styles.

Hopefully it will give you some insight.

Thank you.