gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:56:56 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com