salvois / LargeXlsx

A .net library to write large Excel files in XLSX format with low memory consumption using streamed write.
Other
204 stars 34 forks source link

Since version 1.7.1 the FirstRowNum property is -1 #26

Closed nino-s closed 1 year ago

nino-s commented 1 year ago

Hi,

I have a Unit Test which checks the generated output of a method which uses your library. To check the output, I use NPOI to read the output and the first row to check some header values. Since the version 1.7.1 the test failed with a NullReference, because i access the first row by using sheet.GetRow(0). By further analyzing i came across the FirstRowNum property which is -1.

Here is an example:

using var stream = new MemoryStream();
using (var xlsxWriter = new XlsxWriter(stream))
{
    xlsxWriter
        .BeginWorksheet("Sheet 1")
        .BeginRow().Write("Name").Write("Location").Write("Height (m)")
        .BeginRow().Write("Kingda Ka").Write("Six Flags Great Adventure").Write(139)
        .BeginRow().Write("Top Thrill Dragster").Write("Cedar Point").Write(130)
        .BeginRow().Write("Superman: Escape from Krypton").Write("Six Flags Magic Mountain").Write(126);
}

stream.Seek(0, SeekOrigin.Begin);

IWorkbook workbook;
using (var file = new MemoryStream(stream.ToArray()))
{
    workbook = new XSSFWorkbook(file);
}
Console.WriteLine(workbook.GetSheet("Sheet 1").FirstRowNum);

With the above example using LargeXlsx version 1.7.0 FirstRowNum is 0, with version 1.7.1 FirstRowNum is -1.

It need to have something to do with the line breaks which you added, but I haven't further analyzed it. Can you please have a look on it?

salvois commented 1 year ago

Hi @nino-s , that version of LargeXlsx dropped redundant row numbers from the XLSX files thanks to a pull request that optimized file contents for performance. Looks like NPOI is getting lost not founding those row numbers any longer. Which version of NPOI are you using? Looks that may have been fixed on their side, see https://github.com/nissl-lab/npoi/issues/289 Thanks, Salvo

nino-s commented 1 year ago

Hi @salvois.

Thanks for you research. I used the latest version of DotNetCore.NPOI package. I haven't realized that this package is outdated a long time ago and NPOI can be used and has .NET 6 support. I while check it out on monday and will let you know if everything works as expected.

My test with dotnet fiddle is working with the "new" NPOI package by the way.

Best regards, Nino

nino-s commented 1 year ago

Everything is working fine with the new NPOI package. Thanks for your support!