Hi
I'm developing a web application with Visual Studio 2010, I need open a Excel file without show it to users (is only for update data to a database), for this reazon I used the Workbook class instead the GridWeb class.
I need to kown the number of columns in the worksheet, the Cells.Columns.Count informs 12 columns but it has 15 columns. I read in the help that the WorkSheet class has a ColumnsCount property but this not exist.
The code is:
private void loadExcel1()
{
string path = MapPath("~");
path = path.Substring(0, path.LastIndexOf(\\));
path += @"\\Members.xls";
Workbook workbook = new Workbook(path);
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
Label1.Text = worksheet.Cells.Columns.Count.ToString();
for (int i = 0; i<= worksheet.Cells.Columns.Count; i++)
{
Label2.Text = Label2.Text +"/"+ worksheet.Cells[0, i].StringValue;
}
}
Thanks.
Alejandro
Hi Alejandro,
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 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 complete reference for using these attributes and others in that series, please check the thread: http://www.aspose.com/community/forums/178764/column-and-row-count-invalid/showthread.aspx#178764
Kindly let us know if you still need some clarifications, we would be happy to help you.
Thank you.
Thanks for your response.
The value returned of MaxDataColumn property is the number of excel's columns - 1?
Regards.
Alejandro
Hi,
Well, MaxDataColumn would give the farthest/last index number of the column (zero-based) that has data in it. For example, in your sheet you have data up to Z column, so this property would return 25.
Thank you.