求具体实现代码
Excel解析,2层for循环输出,Excel 2003用 jxl解析,2003以后用poi解析。
private void readBatchFile()
throws Exception {
File file = new File("C:\Users\Administrator\Desktop\test.xlsx");
InputStream in = new FileInputStream(file);
Workbook wb = WorkbookFactory.create(in);
Sheet sheet = wb.getSheetAt(0);
int rowNum = 1;
while (true) {
Row row = sheet.getRow(rowNum++);
if (row == null)
break;
Cell cell = row.getCell(0);
if (cell == null || StringUtils.isBlank(cell.getStringCellValue())) {
break;
}
int n = 0;
Cell c;
for(int i=0;i<10;i++){
c = row.getCell(i);
if (c != null) {
c.setCellType(Cell.CELL_TYPE_STRING);
String s = c.getStringCellValue();
System.out.println("第"+rowNum+"行,第"+i+"列数据:"+s);
}
}
}
}
依赖jar包 :
poi-3.13.jar
poi-ooxml-3.13.jar
poi-ooxml-schemas-3.13.jar
xmlbeans-2.6.0.jar