donnytian / Npoi.Mapper

Use this tool to import or export data with Excel file. The tool is a convention based mapper between strong typed object and Excel data via NPOI.
MIT License
589 stars 114 forks source link

Upgrading NPOI to 2.5.1 throws Field not found: 'NPOI.SS.UserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK' on put #62

Closed andmos closed 4 years ago

andmos commented 4 years ago

👋 After upgrading NPOI package to 2.5.1 (and using Npoi.Mapper 3.4.0) the mapper.Put methods starts throwing

System.MissingFieldException : Field not found: 'NPOI.SS.UserModel.MissingCellPolicy.CREATE_NULL_AS_BLANK'.
   at Npoi.Mapper.Mapper.Put[T](ISheet sheet, IEnumerable`1 objects, Boolean overwrite)
   at Npoi.Mapper.Mapper.Put[T](IEnumerable`1 objects, Int32 sheetIndex, Boolean overwrite)

downgrading to 2.4.1 fixes the problem.

In our code we have

            var meddommerRows = meddommere.Select(TilMeddommerRow).ToList();

            var workbook = WorkbookFactory.Create("Mal_utvalg_tingrett.xlsx");
            var mapper = new Mapper(workbook);
            mapper.Put(meddommerRows);

            var memoryStream = new MemoryStream();
            workbook.Write(memoryStream);
            return memoryStream;

The model getting mapped has column attributes representet in the Excel document, like

        [Column("Etternavn")]
        public string Etternavn { get; set; }

        [Column("Fornavn")]
        public string Fornavn { get; set; }

        [Column("Telefonnummer")]
        public string Telefonnummer { get; set; }

As I said, everything works perfectly with NPOI 2.4.1 and Npoi.Mapper 3.4.0, but upgrading to 2.5.1 starts throwing.

donnytian commented 4 years ago

guys, this is a regression of NPOI itself. I once fixed a bug in NPOI for sheet.RemoveRow(), but in the new release, it was reverted. Not sure what happened there.

this is the PR I fixed the issue for NPOI repository. https://github.com/tonyqus/npoi/pull/91

I am giving up to fix it in NPOI, will find a workaround.

andmos commented 4 years ago

Thanks for the update, @donnytian!

donnytian commented 4 years ago

fixed in v3.4.1