public XWPFHeader createHeader(Enum type, XWPFParagraph[] pars) throws IOException { XWPFRelation relation = XWPFRelation.HEADER; String pStyle = "Header"; int i = getRelationIndex(relation); HdrDocument hdrDoc = HdrDocument.Factory.newInstance(); XWPFHeader wrapper = (XWPFHeader)doc.createRelationship(relation, XWPFFactory.getInstance(), i); CTHdrFtr hdr = buildHdr(type, pStyle, wrapper, pars); wrapper.setHeaderFooter(hdr); OutputStream outputStream = wrapper.getPackagePart().getOutputStream(); hdrDoc.setHdr(hdr); XmlOptions xmlOptions = commit(wrapper); assignHeader(wrapper, type); hdrDoc.save(outputStream, xmlOptions); outputStream.close(); return wrapper; }
/** * Creates a new header of the specified type, to which the * supplied (and previously unattached!) paragraphs are * added to. */ public XWPFHeader createHeader(Enum type, XWPFParagraph[] pars) { XWPFHeader header = getHeader(type); if (header == null) { HdrDocument hdrDoc = HdrDocument.Factory.newInstance(); XWPFRelation relation = XWPFRelation.HEADER; int i = getRelationIndex(relation); XWPFHeader wrapper = (XWPFHeader) doc.createRelationship(relation, XWPFFactory.getInstance(), i); wrapper.setXWPFDocument(doc); CTHdrFtr hdr = buildHdr(type, wrapper, pars); wrapper.setHeaderFooter(hdr); hdrDoc.setHdr(hdr); assignHeader(wrapper, type); header = wrapper; } return header; }
/** * Creates a new header of the specified type, to which the * supplied (and previously unattached!) paragraphs are * added to. */ public XWPFHeader createHeader(Enum type, XWPFParagraph[] pars) { XWPFHeader header = getHeader(type); if (header == null) { HdrDocument hdrDoc = HdrDocument.Factory.newInstance(); XWPFRelation relation = XWPFRelation.HEADER; int i = getRelationIndex(relation); XWPFHeader wrapper = (XWPFHeader) doc.createRelationship(relation, XWPFFactory.getInstance(), i); wrapper.setXWPFDocument(doc); CTHdrFtr hdr = buildHdr(type, wrapper, pars); wrapper.setHeaderFooter(hdr); hdrDoc.setHdr(hdr); assignHeader(wrapper, type); header = wrapper; } return header; }