<%@page import="org.apache.poi.xssf.usermodel.XSSFWorkbook"%> <%@page import="org.apache.poi.xssf.usermodel.XSSFSheet"%> <%@page import="org.apache.poi.xssf.usermodel.XSSFRow"%> <%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%> <%@page import="org.apache.poi.xssf.usermodel.XSSFCell"%>
//Excel文件处理
try { XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(WEBROOT+"/WEB-INF/tmp/"+Calendar.getInstance().getTime().getTime()+"."+tail)); XSSFSheet sheet = wb.getSheetAt(0);//获取工作薄
int totalRows = sheet.getLastRowNum();//获取行数
XSSFRow column = sheet.getRow(0); int totalColumn = column.getLastCellNum();//获取列数
for (int j = 0; j < totalRows; j++) { if(j == 0) continue; XSSFRow sheetrows = sheet.getRow(j); for (int k = 0; k < totalColumn; k++) { XSSFCell cell = sheetrows.getCell((short) k); if(cell!=null){ System.out.println("第" + j + "行 第" + k + "列的值是"+sheetrows.getCell(k).toString()); } } } }catch (Exception e) { e.printStackTrace(); }
|