想用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; }
解决 无用评论 打赏 举报
悬赏问题
- ¥20 matlab计算中误差
- ¥15 对于相关问题的求解与代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料
- ¥15 使用R语言marginaleffects包进行边际效应图绘制
- ¥20 usb设备兼容性问题
- ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊