3

使用 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块中也会使应用程序崩溃):

无法打开工作簿。算术运算导致溢出。

在 Winnovative.ExcelLib.ExcelWorkbook..ctor(流 excelStream,字符串 openPassword,ExcelWorkbookDefaultSettings defaultSettings) 在 Winnovative.ExcelLib.ExcelWorkbook..ctor(流 excelStream)

System.OverflowException 未处理 消息:wnvxls.dll 中发生“System.OverflowException”类型的未处理异常附加信息:算术运算导致溢出。

4

0 回答 0