簡單記錄下Excel表格的讀取方法:
@RequestMapping("/readerExcel")
private void ReaderExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {File f = new File("d:\\wt");//文件地址
File[] flist= f.listFiles();
System.out.println("文件總數:"+flist.length);
HSSFCell cell=null;
String bj="";
//循環目錄
for(int i=0;i<flist.length;i++){
System.out.println("------------當前第"+(i+1)+"個文件,文件名:" + flist[i].getName()+"----------");
FileInputStream is = new FileInputStream(flist[i]);
HSSFWorkbook wbs = new HSSFWorkbook(is);
//循環文件
for(int k = 0; k < wbs.getNumberOfSheets(); k++){
HSSFSheet childSheet = wbs.getSheetAt(k);
String kplx="";
int rowNum = childSheet.getLastRowNum();//行數
star:
for (int j = 2; j <= rowNum; j++) {
HashMap<String,Object> addBMW4S = new HashMap<String,Object>();
HSSFRow row = childSheet.getRow(j);
if(row==null){
continue;
}
if (k==0) {
String bh = row.getCell(8).toString();
String daima = bh.substring(0,bh.length()-2);
/**
* 縣級代碼
*/
String countycityter = row.getCell(3).toString().substring(0,1);
if("N".equals(countycityter)){
addBMW4S.put("SHIJIBIE", "NoneTier");
}else{
addBMW4S.put("SHIJIBIE", countycityter);
}
updateCeate(addBMW4S,daima.substring(0, 4),"CompetitorHistory");
System.out.println(daima+"->"+countycityter);
} else {
}
}