пятница, 6 февраля 2015 г.

C# ExcelDataReader IndexOutOfRangeException error (trying to import Excel File)

Environment

VS 2013
Excel Data Reader library

Problem

I try to import excel file.

With code like this
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);

//1. Reading from a binary Excel file ('97-2003 format; *.xls)
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
//...
//2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
//...
//3. DataSet - The result of each spreadsheet will be created in the result.Tables
DataSet result = excelReader.AsDataSet();

I've got an exception
IndexOutOfRangeException
on some files.

Solution

What've I found out by experimental way: problem files was in old Excel 5-7 format.

"save as" problem files in "excel 97-2003" format and reimport them.

Комментариев нет:

Отправить комментарий