Ashish Jain
Ashish Jain

Reputation: 1

Read a Workbook and add new worksheets then SaveAs(memorystream) using ClosedXML Thorw Exception "Specified method is not supported."

I read an excel workbook using ClosedXML and add new sheets to it. But when I try to workBook.SaveAs(memoryStream), it throws an exception "Specified method is not supported.".

    var responseContent = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
    using var workBook = string.IsNullOrWhiteSpace(model.TemplatePath) ? new XLWorkbook() : new 
    XLWorkbook(responseContent);
    workBook.AddWorksheet("SheetName");
    using var stream = new MemoryStream();
    workBook.SaveAs(stream);
    stream.Position = 0;
    var content = stream.ToArray();

Upvotes: -1

Views: 1714

Answers (1)

Alenros
Alenros

Reputation: 945

Maybe the problem is with an empty responseContent. Running the following adaptation of the code that doesn't contain the responseContent works for me:

     using var workBook = new XLWorkbook();
     workBook.AddWorksheet("SheetName");
     using var stream = new MemoryStream();
     workBook.SaveAs(stream);
     stream.Position = 0;
     var content = stream.ToArray();

Upvotes: 1

Related Questions