在CODE上查看代码片派生到我的代码片 public static Listparse(File file) { List excelValueList = new ArrayList (); if (file.exists() && file.canRead() && (file.getName().lastIndexOf(".xls") >= 1)) { Workbook workbook = null; try { workbook = Workbook.getWorkbook(file); Sheet sheet = workbook.getSheet(0); int row = sheet.getRows(); int col = sheet.getColumns(); for (int r = 0; r < row; r++) { String[] rowValue = new String[col]; for (int c = 0; c < col; c++) { rowValue[c] = sheet.getCell(c, r).getContents() != null sheet .getCell(c, r).getContents() : ""; } excelValueList.add(rowValue); } } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (workbook != null) { workbook.close(); } } } return excelValueList; }
2. Java读取xls文件可以当做是访问
数据库,利用jdbc driver (例如:http://blog.csdn.net/54powerman/article/details/5787402)
出现错误:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
尝试Create a System DSN:http://docs.oracle.com/cd/E18283_01/owb.112/e10582/loading_ms_data.htm#BGBFEGIB
可以用的driver貌似有很多,比如:
sqlsheet: https://code.google.com/p/sqlsheet/
3. 使用jxls或jexcelapi等api来操作,这样可以访问类型更丰富的、布局更复杂的excel。
jxls:
http://jxls.sourceforge.net
jexcelapi:
http://jexcelapi.sourceforge.net/