List of usage examples for org.apache.poi.hssf.usermodel HSSFPictureData getFormat
public int getFormat()
From source file:org.jxstar.report.util.ReportXlsUtil.java
/** * ???1SHEET1SHEET//from w ww. j a v a 2s. c o m * * @param destBook -- * @param srcBook -- ?? */ private static void copySheetImage(HSSFWorkbook destBook, HSSFWorkbook srcBook) { //??? HSSFSheet srcSheet = srcBook.getSheetAt(0); //? HSSFSheet destSheet = destBook.getSheetAt(0); //??? int endRowNum = destSheet.getPhysicalNumberOfRows(); //???? List<HSSFPicture> lsSrcPicture = getAllPicture(srcSheet); _log.showDebug("----------source picture size:" + lsSrcPicture.size()); if (lsSrcPicture.isEmpty()) return; //????? List<HSSFPictureData> lsPicData = null; try { lsPicData = srcBook.getAllPictures(); } catch (Exception e) { _log.showWarn( "book?getAllPictures?book??"); HSSFWorkbook tmpBook = copyWorkbook(srcBook); if (tmpBook != null) { lsPicData = tmpBook.getAllPictures(); tmpBook = null; } /* ???? //??? lsPicData = destBook.getAllPictures(); if (lsPicData == null || lsPicData.isEmpty()) return; //??1? List<HSSFPictureData> destData = FactoryUtil.newList(); for (int i = 0, n = lsSrcPicture.size(); i < n; i++) { destData.add(lsPicData.get(0)); } lsPicData = destData;*/ } if (lsPicData == null || lsPicData.isEmpty()) return; _log.showDebug("----------source data size:" + lsPicData.size()); //???? //????sheet???book if (lsSrcPicture.size() > lsPicData.size()) { _log.showWarn("?????"); return; } //?? HSSFPatriarch destDraw = destSheet.getDrawingPatriarch(); if (destDraw == null) { destDraw = destSheet.createDrawingPatriarch(); } //?? List<HSSFPicture> lsDestPicture = getAllPicture(destSheet); int index = lsDestPicture.size(); for (int i = 0, n = lsSrcPicture.size(); i < n; i++) { //? HSSFPicture picture = lsSrcPicture.get(i); //????? HSSFPictureData picdata = lsPicData.get(i); //?? byte[] datas = picdata.getData(); //??? HSSFClientAnchor anchor = (HSSFClientAnchor) picture.getAnchor(); //?? anchor.setRow1(anchor.getRow1() + endRowNum); anchor.setRow2(anchor.getRow2() + endRowNum); //??? destBook.addPicture(datas, picdata.getFormat()); //???????+1?? index++; _log.showDebug("---------copy new image index=" + index); destDraw.createPicture(anchor, index); } }