java poi導入EXCEL

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;//導入成功!
  }
相關文章
相關標籤/搜索