使用Winnovative的excel库我能够解析包含超链接的excel文件(xls)。当程序直接在我的机器上运行时,它可以工作。如果我尝试将其上传到网站并解析它,完全相同的文件将失败。以下是逻辑示例:
// Works when bytes are parsed from a program running locally.
// Fails when bytes are parsed from a file uploaded to a website
public void TestRead(byte[] bytes)
{
try
{
// Parse excel file
var workBook = new ExcelWorkbook(new MemoryStream(bytes));
// Save file
var toSave = workBook.Save();
System.IO.File.WriteAllBytes(@"C:\Users\[User]\Downloads\Test.xls", toSave);
}
catch (Exception e)
{
}
}
这只是xls
个文件的问题。我在使用超链接解析xlsx
文件时遇到问题。上传的文件无法解析异常(即使它包含在try-catch
块中,也会使应用程序崩溃):
无法打开工作簿。算术运算导致溢出。
at Winnovative.ExcelLib.ExcelWorkbook..ctor(Stream excelStream,String openPassword,ExcelWorkbookDefaultSettings defaultSettings) 在Winnovative.ExcelLib.ExcelWorkbook..ctor(Stream excelStream)
和
System.OverflowException未处理 消息:wnvxls.dll中发生了未处理的“System.OverflowException”类型异常 附加信息:算术运算导致溢出。