EPPlus Excel在1900.01.00之前使用DateTime报告

我想在EPPlus的帮助下创buildExcel报表,但在1900.01.00之前提交date。 在Excel工作表中,它会转换为负数或在Excel中的date位置出现一长串“##### …”行。 我已经设置了格式,但没有帮助:

workSheet.Column(columnIndex).Style.Numberformat.Format = "yyyy.mm.dd."; 

我用这个页面:

http://www.c-sharpcorner.com/article/export-to-excel-in-asp-net-mvc/

MS Excel不识别1900年以前的date。date数字格式是无用的。 您需要在C#中格式化date,并将值作为string,而不是数字。

为了设置数字格式为文本使用:

 workSheet.Column(columnIndex).Style.Numberformat.Format = "@"; 

为了格式化date使用下面的代码,如果date是一个date时间:

 System.IFormatProvider formatProvider = new System.Globalization.CultureInfo("en-US", true);//or a different culture dateTime.ToString("yyyy.MM.dd.", formatProvider))