-1

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.

krisam
  • 60
  • 5

3 Answers3

1

When creating the file, change CreationCollisionOptions from ReplaceExisting to GenerateUniqueName. Then delete the file manually to minimize storage space used up.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Krypto
  • 11
  • 1
0

Finally I used EPPlus 4+ version.

krisam
  • 60
  • 5
-1

Now, NPOI supports dotnet core, and you can install the NPOI NuGet package in UWP project.


Legacy answer:

The NPOI is a nuget library that you should use nuget to install it. See dotnetcore/NPOI: A .NET library for reading and writing Microsoft Office binary and OOXML file formats.

lindexi
  • 4,182
  • 3
  • 19
  • 65
  • 1
    dotnetcore.npoi hasn't been maintained for a long time. Please use https://www.nuget.org/packages/NPOI/ instead – Tony Qu Jan 23 '22 at 08:28