Java將Excel解析爲數組集合

Java將Excel解析爲數組集合

 

相關 jar 包:java

jxl-2.6.jar數組

 

 jar 包下載:http://files.cnblogs.com/files/liaolongjun/excel-jar.zipexcel

 

	/**
	 * 返回上傳的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;
	}
相關文章
相關標籤/搜索