How do I find out the number of columns in a worksheet?

Hello all,

I thought that iterating over columns is appropriate way to do this, however it throws a ArgumentOutOfRangeException when I try to access Columns property in a worksheet that is empty.

static void Main()
{
ExcelEngine engine = new ExcelEngine();
IWorkbook workbook = engine.Excel.Workbooks.Open("c:\\empty.xls");
IWorksheet worksheet = workbook.Worksheets[0];
Console.WriteLine(worksheet.Columns);

}

Thanks,
Andrzej

empty0.zip

1 Reply

MW Melba Winshia Syncfusion Team December 22, 2006 10:34 AM UTC

Hi Andrzej,

Use the following code snippets to find out the number of columns in a worksheet.

[C#]

//Reading number of columns.
Console.WriteLine("No. of columns:"+sheet.Columns.Length.ToString());

Here is the sample for your reference:

NumberOfColumns.zip


Plese take look at the sample above and let me know if you have any other questions.

Thanks,
Melba

Loader.
Up arrow icon