日期:2014-05-16 浏览次数:21123 次
package com.jie.java; import java.io.File; import java.io.FileInputStream; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class ExcelRead { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try{ FileInputStream is = new FileInputStream(new File("c:/最终成绩.xls")); HSSFWorkbook wb=new HSSFWorkbook(is); int sheetNum=wb.getNumberOfSheets(); for(int i=0;i<sheetNum;i++) { HSSFSheet childSheet = wb.getSheetAt(i); int rowNum = childSheet.getLastRowNum(); for(int j=0;j<rowNum;j++) { HSSFRow row = childSheet.getRow(j); int cellNum=row.getLastCellNum(); for(int k=0;k<cellNum;k++) { System.out.print(row.getCell(k).toString()+" "); } System.out.println(); } } }catch(Exception e) { e.printStackTrace(); } } }
if(row!=null){ int cellNum = row.getLastCellNum(); System.out.println("cellNum--"+cellNum); for(int j=0; j<cellNum; j++){ HSSFCell cell = row.getCell(j); if(cell!=null){ System.out.println("sheet "+m+" row "+i+" column "+j+": "+ cell); } } }