System.NullReferenceException Epplus Opening Worksheet

时间:2018-01-23 19:34:52

标签: epplus

I am using Epplus to try to open and read a spreadsheet -- a regular spreadsheet with four columns in xlsx format. I run my code, get the Null Reference error, then tell it to resume and the error is gone. It's like the package isn't fully loaded. I've tried .Sleep(5000) but that doesn't work. I've tried it in and out of USING statement.

        if (!File.Exists(FileName))
        {
            return;
        }
        ExcelPackage pkg = new ExcelPackage(new FileInfo(FileName)); 
        ExcelWorksheet ws = pkg.Workbook.Worksheets.First(); <<-- ERROR HERE

Any help, advice or insight would be greatly appreciated.

2 个答案:

答案 0 :(得分:-1)

我发布此邮件以防其他人遇到此问题。我创建了一个新的Excel文件,它工作正常。我在一堆其他文件上尝试了它并且它有效。

此问题特定于此文件。我不知道是不是因为它有特殊格式或几张 - 无论是什么,特定的Excel文件都会产生问题。

答案 1 :(得分:-2)

我认为EPPLUS无法处理.xls(或旧的excel类型),当我保存具有.xlsx文件类型的新副本时,我也解决了我的问题。它有效!