error in ExceclOpenXmlReader.InitializeSheetReader

Dec 1, 2010 at 9:44 PM

Hi. Sorry for my very "Bad English" (not the wonderful hard rock '80 group...).

I'm doing some tests using the libary. I've created a simple xlsx file using 2007. The file has 1 sheet with 3 cols and 4 rows.

I use this code:

            FileStream stream = File.Open(@"\backup\esempio.xlsx", FileMode.Open, FileAccess.Read);
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

           
            excelReader.IsFirstRowAsColumnNames = true;
            DataSet result = excelReader.AsDataSet();
            while (excelReader.Read())
            {


            }
            excelReader.Close();
            excelReader.Dispose();

when AsDataSet is executed, the _resultIndex member has a "1" value because the file contain 1 sheet.

When excelReader.Read() is called, it invokes InitializeSheetRead() metod.

In InitializeSheetRead() metod there is this instruction:

ReadSheetGlobals(_workbook.Sheets[_resultIndex]);

here an exception is thrown because of _resultIndex has a "1" value. It should be "0"...

Where is my error?

Thanks

Jan 14, 2011 at 11:48 AM

Try this:

            FileStream stream = File.Open(@"\backup\esempio.xlsx", FileMode.Open, FileAccess.Read);
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

            
            excelReader.IsFirstRowAsColumnNames = true;
           
//DataSet result = excelReader.AsDataSet();
            while (excelReader.Read())
            {


            }
            excelReader.Close();
            excelReader.Dispose();