Excel.ExcelReaderFactory无法打开某些文件

时间:2013-10-10 12:16:53

标签: c# excel interop

我在尝试使用Excel.ExcelReaderFactory(http://exceldatareader.codeplex.com/)打开一些xls文件时遇到此错误

IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);

excelReader.IsFirstRowAsColumnNames = false;
DataSet spreadsheetDocument = excelReader.AsDataSet();
  

错误:在文件

中找不到流'Workbook'或'Book'

调用CreateBinaryReader

时发生错误

有些文件100%有效,但有些文件会出现此异常。有没有人有任何想法?

他们网站上的类似问题(http://exceldatareader.codeplex.com/discussions/461766

1 个答案:

答案 0 :(得分:2)

这是http://exceldatareader.codeplex.com/discussions/461766#post1113133我认为我会在这里发布:

同样的问题,与水晶报告xls文件相同的异常。 这是因为“Excel数据读取器”将块字符串定义为“工作簿”和“书籍”,而将Crystal报表定义为“工作簿”:您必须进行不区分大小写的比较!

打开“Excel \ Core \ BinaryFormat \ XlsRootDirectory.cs”并替换第75行

if (e.EntryName == EntryName)

if (string.Equals(e.EntryName, EntryName, StringComparison.CurrentCultureIgnoreCase))

对我来说它解决了。

祝你有愉快的一天, 马可

相关问题