org.apache.poi.xssf.usermodel.XSSFPicture Java Examples
The following examples show how to use
org.apache.poi.xssf.usermodel.XSSFPicture.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PoiPublicUtil.java From autopoi with Apache License 2.0 | 6 votes |
/** * 获取Excel2007图片 * * @param sheet * 当前sheet对象 * @param workbook * 工作簿对象 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData */ public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFWorkbook workbook) { Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); for (POIXMLDocumentPart dr : sheet.getRelations()) { if (dr instanceof XSSFDrawing) { XSSFDrawing drawing = (XSSFDrawing) dr; List<XSSFShape> shapes = drawing.getShapes(); for (XSSFShape shape : shapes) { XSSFPicture pic = (XSSFPicture) shape; XSSFClientAnchor anchor = pic.getPreferredSize(); CTMarker ctMarker = anchor.getFrom(); String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol(); sheetIndexPicMap.put(picIndex, pic.getPictureData()); } } } return sheetIndexPicMap; }
Example #2
Source File: PoiPublicUtil.java From jeasypoi with Apache License 2.0 | 6 votes |
/** * 获取Excel2007图片 * * @param sheet * 当前sheet对象 * @param workbook * 工作簿对象 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData */ public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFWorkbook workbook) { Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); for (POIXMLDocumentPart dr : sheet.getRelations()) { if (dr instanceof XSSFDrawing) { XSSFDrawing drawing = (XSSFDrawing) dr; List<XSSFShape> shapes = drawing.getShapes(); for (XSSFShape shape : shapes) { XSSFPicture pic = (XSSFPicture) shape; XSSFClientAnchor anchor = pic.getPreferredSize(); CTMarker ctMarker = anchor.getFrom(); String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol(); sheetIndexPicMap.put(picIndex, pic.getPictureData()); } } } return sheetIndexPicMap; }
Example #3
Source File: DefaultExcelReader.java From myexcel with Apache License 2.0 | 6 votes |
private void convertPicture(Row row, T obj, Integer index, Field field) { byte[] pictureData; if (isXSSFSheet) { XSSFPicture xssfPicture = xssfPicturesMap.get(row.getRowNum() + "_" + index); if (xssfPicture == null) { return; } pictureData = xssfPicture.getPictureData().getData(); } else { HSSFPicture hssfPicture = hssfPictureMap.get(row.getRowNum() + "_" + index); if (hssfPicture == null) { return; } pictureData = hssfPicture.getPictureData().getData(); } try { field.set(obj, new ByteArrayInputStream(pictureData)); } catch (IllegalAccessException e) { throw new ExcelReadException("Failed to read picture.", e); } }
Example #4
Source File: PoiPublicUtil.java From easypoi with Apache License 2.0 | 6 votes |
/** * 获取Excel2007图片 * * @param sheet * 当前sheet对象 * @param workbook * 工作簿对象 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData */ public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFWorkbook workbook) { Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); for (POIXMLDocumentPart dr : sheet.getRelations()) { if (dr instanceof XSSFDrawing) { XSSFDrawing drawing = (XSSFDrawing) dr; List<XSSFShape> shapes = drawing.getShapes(); for (XSSFShape shape : shapes) { XSSFPicture pic = (XSSFPicture) shape; XSSFClientAnchor anchor = pic.getPreferredSize(); CTMarker ctMarker = anchor.getFrom(); String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol(); sheetIndexPicMap.put(picIndex, pic.getPictureData()); } } } return sheetIndexPicMap; }
Example #5
Source File: ExcelPublicUtil.java From jeewx with Apache License 2.0 | 6 votes |
/** * 获取Excel2007图片 * @param sheet 当前sheet对象 * @param workbook 工作簿对象 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData */ public static Map<String, PictureData> getSheetPictrues07( XSSFSheet sheet, XSSFWorkbook workbook) { Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); for (POIXMLDocumentPart dr : sheet.getRelations()) { if (dr instanceof XSSFDrawing) { XSSFDrawing drawing = (XSSFDrawing) dr; List<XSSFShape> shapes = drawing.getShapes(); for (XSSFShape shape : shapes) { XSSFPicture pic = (XSSFPicture) shape; XSSFClientAnchor anchor = pic.getPreferredSize(); CTMarker ctMarker = anchor.getFrom(); String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol(); sheetIndexPicMap.put(picIndex, pic.getPictureData()); } } } return sheetIndexPicMap; }
Example #6
Source File: SimpleUtils.java From bamboobsc with Apache License 2.0 | 5 votes |
public static void setCellPicture(XSSFWorkbook wb, XSSFSheet sh, byte[] iconBytes, int row, int col) throws Exception { int myPictureId = wb.addPicture(iconBytes, XSSFWorkbook.PICTURE_TYPE_PNG); XSSFDrawing drawing = sh.createDrawingPatriarch(); XSSFClientAnchor myAnchor = new XSSFClientAnchor(); myAnchor.setCol1(col); myAnchor.setRow1(row); XSSFPicture myPicture = drawing.createPicture(myAnchor, myPictureId); myPicture.resize(); }