/** * 使用水印图片作为excel背景,达到水印效果<但打印时不会生效> * @param pkg * @param worksheet * @throws Docx4JException * @throws Exception * @throws IOException */ private void createBgPic(WorksheetPart worksheet) throws Docx4JException { CTSheetBackgroundPicture ctSheetBackgroundPicture = org.xlsx4j.jaxb.Context.getsmlObjectFactory().createCTSheetBackgroundPicture(); worksheet.getContents().setPicture(ctSheetBackgroundPicture); try { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(excelMLPackage, worksheet, FileUtils.readFileToByteArray(imageFile)); Relationship sourceRelationship = imagePart.getSourceRelationships().get(0); String imageRelId = sourceRelationship.getId(); ctSheetBackgroundPicture.setId(imageRelId); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }