Using EPPlus with a MemoryStream

后端 未结 8 1109
离开以前
离开以前 2020-12-05 06:05

I am using EPPlus to generate an XLSX file in C#. As soon as I instantiate the ExcelPackage with a memory stream - I get the error:

\"A disk error occ

8条回答
  •  情深已故
    2020-12-05 06:48

    It looks like you're hitting a bug in the error handler of the ExcelPackage constructor. If you try and give it an empty stream, System.IO.Packaging.Package.Open raises an exception indication that a package cannot be empty.

    This code works, even if the file doesn't exist:

    var file = new FileInfo("test.xlsx");
    using (ExcelPackage package = new ExcelPackage(file))
    {
    }
    

    Given that the documentation for the constructor overload indicates that the stream is allowed to be empty, I'd recommend raising this issue in the EPPlus issue tracker.

提交回复
热议问题