1 public void test() 2 { 3 //获取文件路径 4 string rootFromPath = ConfigurationManager.AppSettings["NPOI"]; 5 //获取文件名 6 string FileName ="123.xlsx"; 7 //创建文件对象 8 FileStream fileStream = new FileStream(rootFromPath+ @"\" + FileName, FileMode.Open, FileAccess.Read); 9 //创建工作簿对象 10 HSSFWorkbook workbook = new HSSFWorkbook(fileStream); 11 //读取工作簿第一张表(此处参数可为下标,也可为表名) 12 ISheet sheet = workbook.GetSheetAt(0); 13 //新建当前工作表行数据 14 IRow row; 15 for (int i = 0; i <= sheet.LastRowNum; i++) 16 { 17 //row读入第i行数据 18 row = sheet.GetRow(i); 19 //获取每一列的数据,并转换为对应的数据类型. 20 string c1 = row.GetCell(1).ToString(); 21 double c2 =System.Convert.ToDouble(row.GetCell(2).ToString()): 0; 22 23 } 24 } 25
原文:https://www.cnblogs.com/zxjiangxiaolong/p/11490477.html