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
601 stars 115 forks source link

Format date with specific date "01/01/0001" #73

Closed loschmitz closed 3 years ago

loschmitz commented 3 years ago

Hi!

It seems there is an error with the date formatting. I need to export this specific date to excel ("01/01/0001") but it didn't work for this date while the other date is working. In my excel generated for the date "01/01/0001", it set me "-1".

Below my code

public byte[] ExportToExcel(IEnumerable exportData, string sheetName = "Sheet1") { using var memoryStream = new MemoryStream(); var mapper = new Mapper(); mapper.UseFormat(typeof(DateTime?), "dd/MM/yyyy"); mapper.UseFormat(typeof(DateTime), "dd/MM/yyyy"); mapper.Save(memoryStream, exportData, sheetName); return memoryStream.ToArray(); }

Thanks in advance!