Using EPPlus with a MemoryStream

后端 未结 8 1112
离开以前
离开以前 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:56

    I know the question was answered months before, but this is how I do it for future reference to anyone trying:

    In VB.NET:

    Dim stream As New MemoryStream
    Using package As New ExcelPackage(stream)
        'Here goes the ExcelPackage code etc 
        package.Save()
    End Using
    

    In C#:

    MemoryStream stream = new MemoryStream();
    using (ExcelPackage package = new ExcelPackage(stream))
    {
        //Here goes the ExcelPackage code etc
        package.Save()
    }
    

    The C# code should be correct, as far as I know. And the ExcelPackage has built-in support for streams.

提交回复
热议问题