/** * save and commit footer */ @Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "ftr")); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); super._getHdrFtr().save(out, xmlOptions); out.close(); }
private void extractFooters(StringBuilder text, XWPFHeaderFooterPolicy hfPolicy) { if (hfPolicy == null) return; if (hfPolicy.getFirstPageFooter() != null) { text.append(hfPolicy.getFirstPageFooter().getText()); } if (hfPolicy.getEvenPageFooter() != null) { text.append(hfPolicy.getEvenPageFooter().getText()); } if (hfPolicy.getDefaultFooter() != null) { text.append(hfPolicy.getDefaultFooter().getText()); } }
XWPFFooter footer = (XWPFFooter) p; footers.add(footer); footer.onDocumentRead(); } else if (relation.equals(XWPFRelation.HEADER.getRelation())) { XWPFHeader header = (XWPFHeader) p;
/** * Creates a new footer of the specified type, to which the * supplied (and previously unattached!) paragraphs are * added to. */ public XWPFFooter createFooter(Enum type, XWPFParagraph[] pars) { XWPFFooter footer = getFooter(type); if (footer == null) { FtrDocument ftrDoc = FtrDocument.Factory.newInstance(); XWPFRelation relation = XWPFRelation.FOOTER; int i = getRelationIndex(relation); XWPFFooter wrapper = (XWPFFooter) doc.createRelationship(relation, XWPFFactory.getInstance(), i); wrapper.setXWPFDocument(doc); CTHdrFtr ftr = buildFtr(type, wrapper, pars); wrapper.setHeaderFooter(ftr); ftrDoc.setFtr(ftr); assignFooter(wrapper, type); footer = wrapper; } return footer; }
void visitFooters(List<XWPFFooter> footers) { if (null == footers) return; for (XWPFFooter footer : footers) { visitParagraphs(footer.getParagraphs()); visitTables(footer.getTables()); } }
/** * Returns the {@link XWPFFooter} of the given footer reference. * * @param footerRef the footer reference. * @return * @throws XmlException * @throws IOException */ protected XWPFFooter getXWPFFooter( CTHdrFtrRef footerRef ) throws XmlException, IOException { PackagePart hdrPart = document.getPartById( footerRef.getId() ); List<XWPFFooter> footers = document.getFooterList(); for ( XWPFFooter footer : footers ) { if ( footer.getPackagePart().equals( hdrPart ) ) { // footer is aleady loaded, return it. return footer; } } // should never come, but load the footer if needed. FtrDocument hdrDoc = FtrDocument.Factory.parse( hdrPart.getInputStream() ); CTHdrFtr hdrFtr = hdrDoc.getFtr(); XWPFFooter ftr = new XWPFFooter( document, hdrFtr ); return ftr; }
public XWPFFooter createFooter(Enum type, XWPFParagraph[] pars) throws IOException { XWPFRelation relation = XWPFRelation.FOOTER; String pStyle = "Footer"; int i = getRelationIndex(relation); FtrDocument ftrDoc = FtrDocument.Factory.newInstance(); XWPFFooter wrapper = (XWPFFooter)doc.createRelationship(relation, XWPFFactory.getInstance(), i); CTHdrFtr ftr = buildFtr(type, pStyle, wrapper, pars); wrapper.setHeaderFooter(ftr); OutputStream outputStream = wrapper.getPackagePart().getOutputStream(); ftrDoc.setFtr(ftr); XmlOptions xmlOptions = commit(wrapper); assignFooter(wrapper, type); ftrDoc.save(outputStream, xmlOptions); outputStream.close(); return wrapper; }
/** * 解析页眉和页脚 * @param doc * @param map * @throws Exception */ private void parseHeaderAndFoot(MyXWPFDocument doc, Map<String, Object> map) throws Exception { List<XWPFHeader> headerList = doc.getHeaderList(); for (XWPFHeader xwpfHeader : headerList) { for (int i = 0; i < xwpfHeader.getListParagraph().size(); i++) { parseThisParagraph(xwpfHeader.getListParagraph().get(i), map); } } List<XWPFFooter> footerList = doc.getFooterList(); for (XWPFFooter xwpfFooter : footerList) { for (int i = 0; i < xwpfFooter.getListParagraph().size(); i++) { parseThisParagraph(xwpfFooter.getListParagraph().get(i), map); } } } }
/** * Returns the picture data of the given image id. * * @param blipId * @return */ protected XWPFPictureData getPictureDataByID( String blipId ) { if ( currentHeader != null ) { return currentHeader.getPictureDataByID( blipId ); } if ( currentFooter != null ) { return currentFooter.getPictureDataByID( blipId ); } return document.getPictureDataByID( blipId ); }
protected XWPFFooter getXWPFFooter( CTHdrFtrRef footerRef ) throws XmlException, IOException { PackagePart hdrPart = document.getPartById( footerRef.getId() ); FtrDocument hdrDoc = FtrDocument.Factory.parse( hdrPart.getInputStream() ); CTHdrFtr hdrFtr = hdrDoc.getFtr(); XWPFFooter ftr = new XWPFFooter(document, hdrFtr); return ftr; }
private void replaceHeaderAndFotter(WordParameterSet parameter) throws WordReplaceException { List<XWPFHeader> headers = document.getHeaderList(); List<XWPFFooter> fotters = document.getFooterList(); for (XWPFHeader header : headers) { processParagraphs(header.getParagraphs(), parameter, document); } for (XWPFFooter footer : fotters) { processParagraphs(footer.getParagraphs(), parameter, document); } }
/** * Returns the {@link XWPFFooter} of the given footer reference. * * @param footerRef the footer reference. * @return * @throws XmlException * @throws IOException */ protected XWPFFooter getXWPFFooter( CTHdrFtrRef footerRef ) throws XmlException, IOException { PackagePart hdrPart = document.getPartById( footerRef.getId() ); List<XWPFFooter> footers = document.getFooterList(); for ( XWPFFooter footer : footers ) { if ( footer.getPackagePart().equals( hdrPart ) ) { // footer is aleady loaded, return it. return footer; } } // should never come, but load the footer if needed. FtrDocument hdrDoc = FtrDocument.Factory.parse( hdrPart.getInputStream() ); CTHdrFtr hdrFtr = hdrDoc.getFtr(); XWPFFooter ftr = new XWPFFooter( document, hdrFtr ); return ftr; }
/** * Creates a new footer of the specified type, to which the * supplied (and previously unattached!) paragraphs are * added to. */ public XWPFFooter createFooter(Enum type, XWPFParagraph[] pars) { XWPFFooter footer = getFooter(type); if (footer == null) { FtrDocument ftrDoc = FtrDocument.Factory.newInstance(); XWPFRelation relation = XWPFRelation.FOOTER; int i = getRelationIndex(relation); XWPFFooter wrapper = (XWPFFooter) doc.createRelationship(relation, XWPFFactory.getInstance(), i); wrapper.setXWPFDocument(doc); CTHdrFtr ftr = buildFtr(type, wrapper, pars); wrapper.setHeaderFooter(ftr); ftrDoc.setFtr(ftr); assignFooter(wrapper, type); footer = wrapper; } return footer; }
/** * 解析页眉和页脚 * @param doc * @param map * @throws Exception */ private void parseHeaderAndFoot(MyXWPFDocument doc, Map<String, Object> map) throws Exception { List<XWPFHeader> headerList = doc.getHeaderList(); for (XWPFHeader xwpfHeader : headerList) { for (int i = 0; i < xwpfHeader.getListParagraph().size(); i++) { parseThisParagraph(xwpfHeader.getListParagraph().get(i), map); } } List<XWPFFooter> footerList = doc.getFooterList(); for (XWPFFooter xwpfFooter : footerList) { for (int i = 0; i < xwpfFooter.getListParagraph().size(); i++) { parseThisParagraph(xwpfFooter.getListParagraph().get(i), map); } } } }
/** * Returns the picture data of the given image id. * * @param blipId * @return */ protected XWPFPictureData getPictureDataByID( String blipId ) { if ( currentHeader != null ) { return currentHeader.getPictureDataByID( blipId ); } if ( currentFooter != null ) { return currentFooter.getPictureDataByID( blipId ); } return document.getPictureDataByID( blipId ); }
private void replaceHeaderAndFotter(WordParameterSet parameter) throws WordReplaceException { List<XWPFHeader> headers = document.getHeaderList(); List<XWPFFooter> fotters = document.getFooterList(); for (XWPFHeader header : headers) { processParagraphs(header.getParagraphs(), parameter, document); } for (XWPFFooter footer : fotters) { processParagraphs(footer.getParagraphs(), parameter, document); } }
/** * Returns the {@link XWPFFooter} of the given footer reference. * * @param footerRef the footer reference. * @return * @throws XmlException * @throws IOException */ protected XWPFFooter getXWPFFooter( CTHdrFtrRef footerRef ) throws XmlException, IOException { PackagePart hdrPart = document.getPartById( footerRef.getId() ); List<XWPFFooter> footers = document.getFooterList(); for ( XWPFFooter footer : footers ) { if ( footer.getPackagePart().equals( hdrPart ) ) { // footer is aleady loaded, return it. return footer; } } // should never come, but load the footer if needed. FtrDocument hdrDoc = FtrDocument.Factory.parse( hdrPart.getInputStream() ); CTHdrFtr hdrFtr = hdrDoc.getFtr(); XWPFFooter ftr = new XWPFFooter( document, hdrFtr ); return ftr; }
InputStream is = null; try { is = getPackagePart().getInputStream(); ftrDocument = FtrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); headerFooter = ftrDocument.getFtr();
/** * 解析页眉和页脚 * @param doc * @param map * @throws Exception */ private void parseHeaderAndFoot(MyXWPFDocument doc, Map<String, Object> map) throws Exception { List<XWPFHeader> headerList = doc.getHeaderList(); for (XWPFHeader xwpfHeader : headerList) { for (int i = 0; i < xwpfHeader.getListParagraph().size(); i++) { parseThisParagraph(xwpfHeader.getListParagraph().get(i), map); } } List<XWPFFooter> footerList = doc.getFooterList(); for (XWPFFooter xwpfFooter : footerList) { for (int i = 0; i < xwpfFooter.getListParagraph().size(); i++) { parseThisParagraph(xwpfFooter.getListParagraph().get(i), map); } } } }
private void extractFooters(StringBuilder text, XWPFHeaderFooterPolicy hfPolicy) { if (hfPolicy == null) return; if (hfPolicy.getFirstPageFooter() != null) { text.append(hfPolicy.getFirstPageFooter().getText()); } if (hfPolicy.getEvenPageFooter() != null) { text.append(hfPolicy.getEvenPageFooter().getText()); } if (hfPolicy.getDefaultFooter() != null) { text.append(hfPolicy.getDefaultFooter().getText()); } }