码迷,mamicode.com
首页 > 其他好文 > 详细

NPOI操作Excel

时间:2015-06-11 18:31:49      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

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             }

 

NPOI操作Excel

标签:

原文地址:http://www.cnblogs.com/Lacey-zhao/p/4569401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!