首页 新闻 会员 周边

NPOI操作

0
悬赏园豆:10 [已解决问题] 解决于 2015-02-17 09:12

npoi 怎么导入相同的值

现在是这样的需求,列的内容有可能完全一致,但是每到data.Columns.Add(column)的时候就会报错

 1  DataTable data = new DataTable();
 2 
 3 
 4             DataColumn column=new DataColumn();
 5             using (FileStream fsRead = File.OpenRead(Path))
 6             {
 7                 //首先创建工作簿
 8                 IWorkbook wk = new HSSFWorkbook(fsRead);
 9                 //读取sheet
10                 for (int i = 0; i < wk.NumberOfSheets; i++)
11                 {
12                     ISheet sheet = wk.GetSheetAt(i);
13                     //定义从第二行开始
14                     for (int r = 1; r <= sheet.LastRowNum; r++)
15                     {
16                         IRow row = sheet.GetRow(r);
17                         //读取单元格内容
18                         for (int c = 1; c < row.LastCellNum; c++)
19                         {
20                             ICell cell = row.GetCell(c);
21 
22                             row.GetCell(7).SetCellType(CellType.STRING);
23                             row.GetCell(8).SetCellType(CellType.STRING);
24                             row.GetCell(9).SetCellType(CellType.STRING);
25                             row.GetCell(10).SetCellType(CellType.STRING);
26                             row.GetCell(11).SetCellType(CellType.STRING);
27                             row.GetCell(12).SetCellType(CellType.STRING);
28                             if (cell != null)
29                             {
30                                
31                                 string cellValue = Convert.ToString(cell.StringCellValue);
32 
33                              35                                     column = new DataColumn(cellValue);
36 37                             }
38                             data.Columns.Add(column);
39                         }
40                     }
41                 }
42             }
43             return data;
View Code

大神呀,百度了半天也没有找到合适的解决方案,求大神解惑,谢谢

_Vegetables的主页 _Vegetables | 小虾三级 | 园豆:586
提问于:2015-02-17 01:10
< >
分享
最佳答案
0

直接给复制吧,然后加一个记录文件就OK了,何必放到datacolumn中呢,哈哈

_Vegetables | 小虾三级 |园豆:586 | 2015-02-17 09:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册