String path = request.getServletContext().getRealPath("/upload/Excel");
if (file.exists()){
File[] files=file.listFiles();
if (files.length==0){
System.out.println("文件夹为空");
return;
}else {
for(File file2:files){
String filename=file2.getName();
String newFileName = filename.substring(filename.lastIndexOf("."));
if (newFileName.equals(".xls")){
filename=filename.substring(0,filename.lastIndexOf("."));
if (filename.equals(excelname)){

try {
Workbook rwb=Workbook.getWorkbook(file2);
Sheet rs=rwb.getSheet(0);//或者rwb.getSheet(0)
int clos=rs.getColumns();//得到所有的列
int rows=rs.getRows();//得到所有的行

System.out.println(clos+" rows:"+rows);
for (int i = 0; i < rows; i++) {
Map<String,String> map=new HashMap<>();
for (int j = 0; j < clos; j++) {
map.put(j+"",rs.getCell(j,i).getContents());
}
mapList.add(map);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
 posted on 2019-07-03 16:18  技术的深奥  阅读(416)  评论(0编辑  收藏  举报