org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy.buildHdr()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy.buildHdr()方法的一些代码示例,展示了XWPFHeaderFooterPolicy.buildHdr()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XWPFHeaderFooterPolicy.buildHdr()方法的具体详情如下:
包路径:org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy
类名称:XWPFHeaderFooterPolicy
方法名:buildHdr

XWPFHeaderFooterPolicy.buildHdr介绍

[英]MB 24 May 2010. Created this overloaded buildHdrFtr() method because testing demonstrated that the XWPFFooter or XWPFHeader object returned by calls to the createHeader(int, XWPFParagraph[]) and createFooter(int, XWPFParagraph[]) methods or the getXXXXXHeader/Footer methods where headers or footers had been added to a document since it had been created/opened, returned an object that contained no XWPFParagraph objects even if the header/footer itself did contain text. The reason was that this line of code; CTHdrFtr ftr = CTHdrFtr.Factory.newInstance(); created a brand new instance of the CTHDRFtr class which was then populated with data when it should have recovered the CTHdrFtr object encapsulated within the XWPFHeaderFooter object that had previoulsy been instantiated in the createHeader(int, XWPFParagraph[]) or createFooter(int, XWPFParagraph[]) methods.
[中]MB 2010年5月24日。创建此重载buildHdrFtr()方法是因为测试表明,通过调用createHeader(int,XWPFParagraph[])和createFooter(int,XWPFParagraph[])方法或GetxxxxshHeader/Footer方法返回的Xwpfooter或XWPFHeader对象自创建/打开文档以来已将页眉或页脚添加到文档中,返回的对象不包含XWPFParagraph对象,即使页眉/页脚本身包含文本。原因是这行代码;CTHdrFtr ftr=CTHdrFtr。工厂newInstance();创建了CTHDRFtr类的一个全新实例,然后在该类本应恢复封装在XWPFHeaderFooter对象中的CTHDRFtr对象时,用数据填充该实例,该对象先前已在createHeader(int,XWPFParagraph[])或createFooter(int,XWPFParagraph[])方法中实例化。

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * 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;
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

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;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * 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;
}

相关文章