标签:
import jxl.DateCell; import jxl.NumberCell; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public String txtTableImport(String tableName, String path, HttpServletRequest request) { File dataFile = new File(path); try { // 导入excel文件 FileInputStream is=new FileInputStream(dataFile); HSSFWorkbook wbs = new HSSFWorkbook(is); HSSFSheet childSheet = wbs.getSheetAt(0); int x = childSheet.getLastRowNum(); // 有 X 行 for(int j=1; j<=x;j++ ){ HSSFRow row = childSheet.getRow(j); int y = row.getLastCellNum() ; // 有Y列 String name= GlobalFunc.toString(row.getCell(0)); //读取列的值 String age GlobalFunc.toString(row.getCell(1)); //读取列的值 } } catch (Exception e) { e.printStackTrace(); return Constants.uploadFail; //导入失败:未知错误! } logger.debug("data import successfully!"); return Constants.uploadSuccess;//导入成功! }
标签:
原文地址:http://my.oschina.net/u/2242194/blog/403389