Java将Excel解析为数组集合
相关 jar 包:
jxl-2.6.jar
jar 包下载:http://files.cnblogs.com/files/liaolongjun/excel-jar.zip
/** * 返回上传的Excel表格的内容 */ public static List<String[]> parseExcel(InputStream is) throws Exception { List<String[]> 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; }
时间: 2024-11-11 03:45:46