Search code examples
c#.netexceluwpnpoi

Creating an Excel File with NPOI on UWP


I'm developing an UWP application that gets information about assets, groups them into batches and creates an Excel with that info.

I'm using NPOI library and it doesnt throw any exception, but the excel file can't be read.

My summarized code is something like:

using(NPOIStream stream = new NPOIStream())  //<-- Not important. An overriden MemoryStream
{
   IWorkbook workbook = new XSSFWorkbook();
   // I fill my XSSFWorkbook

   workbook.Write(stream);

   byte[] buffer = stream.GetBuffer();

   // StorageFolder folder is already picked
   StorageFile = await folder.CreateFileAsync("sample.xlsx", CreationCollisionOption.ReplaceExisting);

   await FileIO.WriteByteAsync(file, buffer);
}

Any help is welcome.


Solution

  • Finally I used EPPlus 4+ version.