protected void init() { try { template = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result.getWorkbook().getCalcPr().setCalcMode(STCalcMode.AUTO); result.getWorkbook().getCalcPr().setFullCalcOnLoad(true); marshaller = XmlCopyUtils.createMarshaller(Context.jcSML); unmarshaller = XmlCopyUtils.createUnmarshaller(Context.jcSML); } catch (Exception e) { throw wrapWithReportingException(String.format("An error occurred while loading template [%s]", reportTemplate.getDocumentName()), e); } }
protected void init() { try { template = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result.getWorkbook().getCalcPr().setCalcMode(STCalcMode.AUTO); result.getWorkbook().getCalcPr().setFullCalcOnLoad(true); marshaller = XmlCopyUtils.createMarshaller(Context.jcSML); unmarshaller = XmlCopyUtils.createUnmarshaller(Context.jcSML); } catch (Exception e) { throw wrapWithReportingException(String.format("An error occurred while loading template [%s]", reportTemplate.getDocumentName()), e); } }
/** * 传入一个 xlsx 文件,和一个水印文件,给这个 xlsx 文件加水印 * @author eko.zhan at 2018年9月17日 下午2:10:50 * @throws Docx4JException * @throws Xlsx4jException */ @Override public void process() throws WatermarkException { try { SpreadsheetMLPackage excelMLPackage = SpreadsheetMLPackage.load(file); this.excelMLPackage = excelMLPackage; int size = excelMLPackage.getWorkbookPart().getContents().getSheets().getSheet().size(); for (int i=0;i<size;i++) { WorksheetPart worksheet = excelMLPackage.getWorkbookPart().getWorksheet(i); createBgPic(worksheet); } excelMLPackage.save(file); } catch (Docx4JException e) { throw new WatermarkException("Docx4JException", e); } catch (Xlsx4jException e) { throw new WatermarkException("Xlsx4jException", e); } }