想用java代码读取excel(2013)表格里的内容,但是excel里面有好几个sheet,还有好几个表,该怎么办,而且还要把读取出来的内容储存到数据库中去,求大神帮助
3条回答
- 咚咚swwadaw 2016-02-16 09:01关注
public static List<String[]> readExcel(String filePath) { try { List<String[]> list = new ArrayList<String[]>(); InputStream in = new FileInputStream(filePath); Workbook book = null; if (filePath.endsWith(".xls")) { book = new HSSFWorkbook(in); } else if (filePath.endsWith(".xlsx")) { book = new XSSFWorkbook(in); } // HSSFWorkbook hssfWorkbook = new HSSFWorkbook(in); // 循环工作表Sheet for (int i = 0; i < book.getNumberOfSheets(); i++) { Sheet sheet = book.getSheetAt(i); if (sheet == null) { continue; } // 循环行Row for (int j = 1; j <= sheet.getLastRowNum(); j++) { Row row = sheet.getRow(j); if (row == null) { continue; } String[] values = new String[row.getLastCellNum()]; for (int k = 0; k < row.getLastCellNum(); k++) { Cell xh = row.getCell(k); if (xh == null) { continue; } values[k] = getValue(xh); } list.add(values); } } return list; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 fluent的在模拟压强时使用希望得到一些建议
- ¥15 STM32驱动继电器
- ¥15 Windows server update services
- ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
- ¥15 模糊pid与pid仿真结果几乎一样
- ¥15 java的GUI的运用
- ¥15 Web.config连不上数据库
- ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
- ¥15 怎么配置广告联盟瀑布流
- ¥15 Rstudio 保存代码闪退