c# - Codeplex Excel 数据阅读器为 Excel 2010 提供空数据集

标签 c# excel codeplex

我正在使用 Codeplex Excel 数据阅读器来读取 excel。我面临的问题是它可以毫无困难地读取 Excel 97-2003 文档,但是当使用 ExcelReaderFactory.CreateOpenXmlReader(stream) 读取 Excel 207-2010 文档时,它输出的是一个空数据集。有没有人遇到过这个问题。有没有人对此有任何解决方案?

读取方法如下

private DataSet ReadExcel(string fileName, string extention)

{

    DataSet dsData = null;
    FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read);
    IExcelDataReader excelReader = null;

    try
    {

        if (extention.Equals("xls"))
        {
            //1. Reading from a binary Excel file ('97-2003 format; *.xls)
            excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
        }
        else
        {
            //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
            excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
           // excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
        }

        excelReader.IsFirstRowAsColumnNames = false;
        dsData = excelReader.AsDataSet();
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        if (excelReader != null)
        {
            excelReader.Close();
        }
    }
    return dsData;
}

最佳答案

8000401a 表示它与 Run As Logon Failure 有关。

避开server-side automation of office .或者使用 XML 在服务器上处理 Excel 电子表格。

根据support issues with the Excel Data Reader :

Design and usage are great. So far only issue I've had is with certain XLSX file not parsing correctly (reading in wrong sheets, missind cell values, etc). To resolve these issues, I had to rebuild Excel.dll using latest SharpZipLib from http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx. As others have said, project needs an update, but is still good.

或者只使用标准的 microsoft 方式:

Microsoft.Office.Interop.Excel.Application xlApp;
Workbook wb = null;
try
{
wb = xlApp.Workbooks.Open(filePath, false, true,5,null,"WrongPAssword");
}

foreach (object possibleSheet in wb.Sheets)
   {
   var aSheet = possibleSheet as Worksheet;
     if (aSheet != null)
     {
....

关于c# - Codeplex Excel 数据阅读器为 Excel 2010 提供空数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11876669/

相关文章:

c# - ASP.NET FaceBook 应用程序开发 -

c# - 了解 XAML/WPF 中的样式和模板

c# - 使用 .replace 替换文本文档中的单词 (c#)

Excel VBA循环代码

python - 如果某些列有交集,如何将行从一张纸复制到另一张纸

excel - 可以使用条件格式来更改内容而不仅仅是单元格的格式吗?

c# - 更新 Active Directory 用户登录名域

c# - 接口(interface)顺序的意义

github - 为什么 TypeScript 迁移到 GitHub?

.net - (自动)将 CodePlex 项目迁移到 GitHub