我已经从 Visual Studio 包管理器控制台下载了 ExcelDataReader,并按照其 Code Plex 页面http://exceldatareader.codeplex.com/上的 C# 说明进行操作,但是,在运行时,我得到一个“找不到 ExcelReaderFactory.cs” ExcelReaderFactory 代码失败时的消息。我的整个代码块如下。
我已经尝试删除并重新安装 Nuget 包并搜索了几个小时,从这个站点得到了答案:ExcelReaderFactory.cs not found。我尝试捕捉一个可能的异常,但我的代码中没有捕捉到任何异常。异常是否仅在 ExcelDataReader 源代码中,我无权访问,而不是在我的代码中?这个错误的解决方案是什么?首先十分感谢。
[HttpPost]
public ActionResult UploadForecasts(HttpPostedFileBase ForecastsFile)
{
try
{
string myPath = "C:\\Uploads\\" + ForecastsFile.FileName;
ForecastsFile.SaveAs(myPath);
System.IO.FileStream stream = System.IO.File.Open(myPath, FileMode.Open, FileAccess.Read);
IExcelDataReader ForecastsReader = myPath.Contains(".xlsx")
? Excel.ExcelReaderFactory.CreateOpenXmlReader(stream)
: Excel.ExcelReaderFactory.CreateBinaryReader(stream);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}