NPOI操作Excel

1、转载地址:http://www.cnblogs.com/knowledgesea/archive/2012/11/16/2772547.html

2、日期的处理

     row.CreateCell(0, CellType.NUMERIC).SetCellValue(employees[i].InDate);

     要设置CellStyle

     ICellStyle styledate = hssfworkbook.CreateCellStyle();

     IDataFormat format = hssfworkbook.CreateDataFormat();

      styledate.DataFormat = format.GetFormat("yyyy\"年\"m\"月\"d\"日\"");

3、code

 

 1 for (int i = 0; i < employees.Length; i++)

 2             {

 3                 IRow row = sheet.CreateRow(i+1);

 4                 row.CreateCell(0, CellType.STRING).SetCellValue(employees[i].Name);

 5                 row.CreateCell(1, CellType.STRING).SetCellValue(employees[i].Number);

 6                 //日期

 7                 ICellStyle styledata = book.CreateCellStyle();

 8                 IDataFormat format = book.CreateDataFormat(); 

 9                 styledata.DataFormat = format.GetFormat("yyyy年m月d日");

10                 ICell cell = row.CreateCell(2, CellType.NUMERIC);

11                 cell.CellStyle = styledata;

12                 cell.SetCellValue(employees[i].InDate);

13                 //日期

14 

15             }

 

你可能感兴趣的:(Excel)