Excel 图片
/** * 获取图片 * Excel文件中某一列都为图片 多列图片这里需要读取指定的列c1 * * @param workbook workbook * @param siteImgMap Map<Integer,List<byte[]>> siteImgMap多图片 */ private void arrangeExcelImg(XSSFWorkbook workbook, Map<Integer, byte[]> siteImgMap) { if (workbook.getSheetAt(0).getDrawingPatriarch() != null) { for (XSSFShape shape : workbook.getSheetAt(0).getDrawingPatriarch().getShapes()) { XSSFClientAnchor anchor = (XSSFClientAnchor) shape.getAnchor(); if (shape instanceof XSSFPicture) { XSSFPicture pic = (XSSFPicture) shape; short c1 = anchor.getCol1();//列 int r1 = anchor.getRow1(); //行 XSSFPictureData pictureData = pic.getPictureData(); byte[] imageData = pictureData.getData(); siteImgMap.put(r1, imageData); } } } }
调用方法: 注意类似电话号码需要额外处理例如正则表达式去除非数字字符等
//上传的Excel文件 Workbook workbook = new XSSFWorkbook(file.getInputStream()); //总图片 Map<Integer, byte[]> siteImgMap = new HashMap<>(); this.arrangeExcelImg((XSSFWorkbook) workbook, siteImgMap); //获取sheet 化粪池基础信息台账 Sheet sheet = workbook.getSheetAt(0); //总行数 int lastRowNum = sheet.getLastRowNum(); List<ImportEchoListVO> listVOList = new ArrayList<>(); for (int i = 3; i <= lastRowNum; i++) { //获取当前Sheet 单元格第 i_行 0_列 值 PoiCellUtil.getCellValue(sheet, i, 0).replaceAll("[^\\d]", ""); // 返回纯数字格式的电话号码
}
参考:https://www.cnblogs.com/mystyle123/p/15806480.html https://www.cnblogs.com/liang-shi/p/16812900.html