Search code examples
c#npoi

NPOI not write all cells out or removed wrong row


I am using NPOI 2.1.3.1 to write out a workbook but I got a blank header after write to file.

Detailed operation is:

  1. Load an existing xlsx file into memory

    Workbook = WorkbookFactory.Create(stream);

  2. I took the first row/header to lookup some values, but don't change anything on it.

    var firstRow = sheet.GetRow(sheet.FirstRowNum);
    var columns = GetColumns(firstRow);
    // Set other cells, but didn't touch the header...

  3. Removed the 2nd row and create a new row as the 2nd row.

    sheet.RemoveRow(row);
    sheet.CreateRow(1);

  4. Save the workbook to another file using Write method.

The problem is the saved file is missing the header values. enter image description here

And when I debug into the code and check the workbook after the Write enter image description here

The header cells were still there. What happened for Write method?


Solution

  • This is confirmed as a bug for NPOI.

    ISheet.RemoveRow has removed wrong row from underlying data list.

    I've submited pull request and hopefully can be resolved in next release of NPOI.