org.apache.poi.xwpf.usermodel.XWPFDocument.getHeaderFooterPolicy()方法的使用及代码示例

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

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

XWPFDocument.getHeaderFooterPolicy介绍

[英]Returns the policy on headers and footers, which also provides a way to get at them.
[中]返回页眉和页脚的策略,这也提供了获取页眉和页脚的方法。

代码示例

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

public String getText() {
  StringBuilder text = new StringBuilder(64);
  XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
  // Start out with all headers
  extractHeaders(text, hfPolicy);
  // Process all body elements
  for (IBodyElement e : document.getBodyElements()) {
    appendBodyElementText(text, e);
    text.append('\n');
  }
  // Finish up with all the footers
  extractFooters(text, hfPolicy);
  return text.toString();
}

代码示例来源:origin: apache/tika

protected void buildXHTML(XHTMLContentHandler xhtml)
    throws SAXException, XmlException, IOException {
  XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
  XWPFListManager listManager = new XWPFListManager(document.getNumbering());

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

public String getText() {
  StringBuilder text = new StringBuilder(64);
  XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
  // Start out with all headers
  extractHeaders(text, hfPolicy);
  // Process all body elements
  for (IBodyElement e : document.getBodyElements()) {
    appendBodyElementText(text, e);
    text.append('\n');
  }
  // Finish up with all the footers
  extractFooters(text, hfPolicy);
  return text.toString();
}

代码示例来源:origin: stackoverflow.com

String text = "Test";
 File docxFile = new File("C:/testeXWPF.docx");
 FileInputStream finStream = new FileInputStream(docxFile.getAbsolutePath());
 XWPFDocument doc = new XWPFDocument(finStream);
 XWPFHeaderFooterPolicy policy = doc.getHeaderFooterPolicy();
 if (policy == null) {
   policy = new XWPFHeaderFooterPolicy(doc);
 }
 CTP ctP1 = CTP.Factory.newInstance();
 CTR ctR1 = ctP1.addNewR();
 CTText t = ctR1.addNewT();
 t.setStringValue(text);
 XWPFParagraph codePara = new XWPFParagraph(ctP1);
 XWPFParagraph[] newparagraphs = new XWPFParagraph[1];
 newparagraphs[0] = codePara;
 policy.createFooter(policy.DEFAULT, newparagraphs);
 FileOutputStream fileOut = new FileOutputStream(docxFile);
 doc.write(fileOut);
 fileOut.close();

代码示例来源:origin: stackoverflow.com

public void test1() throws IOException{

  XWPFDocument sampleDoc = new XWPFDocument();
  XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
  //in an empty document always will be null
  if(policy==null){
    CTSectPr sectPr = sampleDoc.getDocument().getBody().addNewSectPr();
    policy = new  XWPFHeaderFooterPolicy( sampleDoc, sectPr );
  }

  if (policy.getDefaultHeader() == null && policy.getFirstPageHeader() == null
      && policy.getDefaultFooter() == null) {
    XWPFHeader headerD = policy.createHeader(policy.DEFAULT);
    headerD.getParagraphs().get(0).createRun().setText("Hello Header World!");

  } 
  FileOutputStream out = new FileOutputStream(System.currentTimeMillis()+"_test1_header.docx");
  sampleDoc.write(out);
  out.close();
  sampleDoc.close();
}

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers

/**
 * @see org.apache.poi.xwpf.extractor.XWPFWordExtractor#getText()
 */
@Override
protected void buildXHTML(XHTMLContentHandler xhtml)
    throws SAXException, XmlException, IOException {
  XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
  XWPFListManager listManager = new XWPFListManager(document.getNumbering());
  // headers
  if (hfPolicy != null) {
    extractHeaders(xhtml, hfPolicy, listManager);
  }
  // process text in the order that it occurs in
  extractIBodyText(document, listManager, xhtml);
  // then all document tables
  if (hfPolicy != null) {
    extractFooters(xhtml, hfPolicy, listManager);
  }
}

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

public String getText() {
  StringBuffer text = new StringBuffer();
  XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();

代码示例来源:origin: ekoz/kbase-doc

private void addWaterMark(Object obj, String watermark, String color) {
    if (obj instanceof XWPFDocument) {
      XWPFDocument doc = (XWPFDocument) obj;
      // create header-footer
      XWPFHeaderFooterPolicy headerFooterPolicy = doc.getHeaderFooterPolicy();
      if (headerFooterPolicy == null) headerFooterPolicy = doc.createHeaderFooterPolicy();
      
      // create default Watermark - fill color black and not rotated
      headerFooterPolicy.createWatermark(watermark);
      
      // get the default header
      // Note: createWatermark also sets FIRST and EVEN headers 
      // but this code does not updating those other headers
      XWPFHeader header = headerFooterPolicy.getHeader(XWPFHeaderFooterPolicy.DEFAULT);
      XWPFParagraph paragraph = header.getParagraphArray(0);
      
      // get com.microsoft.schemas.vml.CTShape where fill color and rotation is set
      XmlObject[] xmlobjects = paragraph.getCTP().getRArray(0).getPictArray(0).selectChildren(new QName("urn:schemas-microsoft-com:vml", "shape"));
      if (xmlobjects.length > 0) {
        com.microsoft.schemas.vml.CTShape ctshape = (com.microsoft.schemas.vml.CTShape)xmlobjects[0];
        // set fill color
        ctshape.setFillcolor(color);
        // set rotation
        ctshape.setStyle(ctshape.getStyle() + ";rotation:315");
      }
    } else if (obj instanceof HWPFDocument) {
      
    }
  }
}

代码示例来源:origin: org.apache.tika/tika-parsers

protected void buildXHTML(XHTMLContentHandler xhtml)
    throws SAXException, XmlException, IOException {
  XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
  XWPFListManager listManager = new XWPFListManager(document.getNumbering());

相关文章

XWPFDocument类方法