WorkbookFactory.Create()函数读取已存在文件; 单个Cell有多个格式数据,读取之前确认要读取的是哪一种格式; 假如cell里面我敲了一串string进去,然后在代码里面用Cell.NumericCellValue来读取的话,就会崩掉;
public static void GetDataFromExcel(string path) { IWorkbook excel = WorkbookFactory.Create(path); ISheet sheet1 = excel.GetSheetAt(0); IRow row_num1 = sheet1.GetRow(0); IRow row_num2 = sheet1.GetRow(1); for (int i = 0; i < 10; i++) { ICell cell = row_num2.Cells[i]; Console.WriteLine(cell.StringCellValue); //ICell tempCell = row_num1.Cells[i]; //Console.WriteLine(tempCell.NumericCellValue); // row_num2.CreateCell(i).SetCellValue(Convert.ToInt32( tempCell.StringCellValue)*2); } }