Only imports column if you resize it?

Hi,

I am currently evaluating Aspose.Cells and have run into the following problem.

I have a very simple excel document that has 1 column. It looks as follows:

Col1
Val1
Val2

When I open the workbook and test how many columns there are it returns 0? When I test the number of columns it evaluate to 3 as it should. The strange thing is that if I resize the column in Excel and then open it with my app, it does return the column?

Any help would be appreciated.

Hi,

Thanks for considering Aspose.

Kindly note the description of the following properties / methods. You may choose them for your need.

Cells.MaxColumn property is used to get the Maximum Column index (zero-based) which contains data / style attribute. Cells.MaxDataColumn property is used to get the Maximum Column index which contains data only. Cells. Cells.MaxDataRowInColumn() method returns the Maximum row index which contains data in a column, it takses column number as an argument Cells.MaxRow property is used to get the Maximum Row index which contains data / having style attribute. Cells.MaxDataRow property is used to get the Maximum Row index which contains data only.

I write the following code for you. I use a template file tstbk1.xls having data in the first column A. And at H18 cell, I fill some background color (Light Green) :

Col1
Val1
Val2

Workbook wb = new Workbook();

wb.Open(@"d:\test\tstbk1.xls");

Worksheet ws = wb.Worksheets[0];

int maxcol = ws.Cells.MaxColumn;

int maxdatacol = ws.Cells.MaxDataColumn;

int maxdatarowincol = ws.Cells.MaxDataRowInColumn(0);

int maxrow = ws.Cells.MaxRow;

int maxdatarow = ws.Cells.MaxDataRow;

MessageBox.Show("Max Column index which contains data / style attribute: " + maxcol.ToString());//..................returns 7... ok bcoz H column index is 7.

MessageBox.Show("Max Column index which contains data only: " + maxdatacol.ToString());//.........returns 0...ok as data contains only in the first column.

MessageBox.Show("Max row index which contains data in the first column: " + maxdatarowincol.ToString());//.........returns 2...ok as the first column has 3 rows filled.

MessageBox.Show("Max Row index which contains data / style attribute:" + maxrow.ToString());//...........returns 17.... ok. as H18 is cell which contains style color.

MessageBox.Show("Max Row index which contains data only" + maxdatarow.ToString());//.......... returns 2...ok as data is filled (A1...A3) first 3 rows.

Thank you.

Hi Amjad,

Thanks for the reply. We were using something like this:

Cells.ExportDataTableAsString(0, 0, ws.Cells.Rows.Count, ws.Cells.Columns.Count)

This was returning an empty DataTable. This seemed like the natural way of using the Columns collection until I read the documentation. It states: “If a column has a default setting, it will not occur in this collection.” I’m assuming that “default settings” == “style settings”?

Cheers





Hi,

Well, Cells.Columns collection will include those columns which have other than the standard width settings. You should use your code like:

Cells.ExportDataTableAsString(0, 0, ws.Cells.MaxRow, ws.Cells.MaxColumn)

You can access a particular column in the worksheet using the indexer in the columns collection in the worksheet.i.e., ... Cells.Columns[0]

Thank you.