Java将Excel解析为数组集合
相关 jar 包:
jxl-2.6.jar
/**
* 返回上传的Excel表格的内容
*/
public static List parseExcel(InputStream is) throws Exception {
List list = new ArrayList<>();
Workbook wb = Workbook.getWorkbook(is);
Sheet sheet = wb.getSheets()[0];
int columns = sheet.getRow(0).length;
for (int i = 0; i < sheet.getRows(); i++) {
String[] line = new String[columns];
for (int j = 0; j < columns; j++) {
Cell cell = sheet.getCell(j, i);
String content = null;
if (cell != null) {
content = cell.getContents();
}
if (content != null && content.trim().length() == 0) {
content = null;
}
line[j] = content;
}
list.add(line);
}
return list;
}