public static List<String[]> parseExcel(String filePath) {
File file = new File(filePath);
List<String[]> excelValueList = new ArrayList<String[]>();
if(file.exists() && file.canRead() && file.getName().lastIndexOf(".xls")>=1) {
Workbook workbook = null;
try {
//构建Workbook对象
workbook = Workbook.getWorkbook(file);
//获取sheet表
Sheet[] sheets = workbook.getSheets();
if(sheets !=null && sheets.length>0){
for(int s = 0;s<sheets.length;s++){
//获表的列
int cols = sheets[s].getColumns();
//获表的行
int rows = sheets[s].getRows();
//表中的所有单元格
Cell cell[][] = new Cell[cols][rows];
for(int i = 1; i < rows; i++) {
String[] rowValue = new String[cols];
for(int j = 0; j < cols; j++) {
cell[j][i] = sheets[s].getCell(j, i);
rowValue[j] = cell[j][i].getContents()!=null?
cell[j][i].getContents():" ";
}
excelValueList.add(rowValue);
}
}
}
}catch (BiffException e) {
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
}finally {
if(workbook != null) {
workbook.close();
}
}
}
return excelValueList;
}