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

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

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

XWPFHeaderFooterPolicy.getHeader介绍

[英]Get the header that applies to the given (1 based) page.
[中]获取适用于给定(基于1)页面的标题。

代码示例

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

  1. /**
  2. * Creates a new header of the specified type, to which the
  3. * supplied (and previously unattached!) paragraphs are
  4. * added to.
  5. */
  6. public XWPFHeader createHeader(Enum type, XWPFParagraph[] pars) {
  7. XWPFHeader header = getHeader(type);
  8. if (header == null) {
  9. HdrDocument hdrDoc = HdrDocument.Factory.newInstance();
  10. XWPFRelation relation = XWPFRelation.HEADER;
  11. int i = getRelationIndex(relation);
  12. XWPFHeader wrapper = (XWPFHeader) doc.createRelationship(relation,
  13. XWPFFactory.getInstance(), i);
  14. wrapper.setXWPFDocument(doc);
  15. CTHdrFtr hdr = buildHdr(type, wrapper, pars);
  16. wrapper.setHeaderFooter(hdr);
  17. hdrDoc.setHdr(hdr);
  18. assignHeader(wrapper, type);
  19. header = wrapper;
  20. }
  21. return header;
  22. }

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

  1. private void addWaterMark(Object obj, String watermark, String color) {
  2. if (obj instanceof XWPFDocument) {
  3. XWPFDocument doc = (XWPFDocument) obj;
  4. // create header-footer
  5. XWPFHeaderFooterPolicy headerFooterPolicy = doc.getHeaderFooterPolicy();
  6. if (headerFooterPolicy == null) headerFooterPolicy = doc.createHeaderFooterPolicy();
  7. // create default Watermark - fill color black and not rotated
  8. headerFooterPolicy.createWatermark(watermark);
  9. // get the default header
  10. // Note: createWatermark also sets FIRST and EVEN headers
  11. // but this code does not updating those other headers
  12. XWPFHeader header = headerFooterPolicy.getHeader(XWPFHeaderFooterPolicy.DEFAULT);
  13. XWPFParagraph paragraph = header.getParagraphArray(0);
  14. // get com.microsoft.schemas.vml.CTShape where fill color and rotation is set
  15. XmlObject[] xmlobjects = paragraph.getCTP().getRArray(0).getPictArray(0).selectChildren(new QName("urn:schemas-microsoft-com:vml", "shape"));
  16. if (xmlobjects.length > 0) {
  17. com.microsoft.schemas.vml.CTShape ctshape = (com.microsoft.schemas.vml.CTShape)xmlobjects[0];
  18. // set fill color
  19. ctshape.setFillcolor(color);
  20. // set rotation
  21. ctshape.setStyle(ctshape.getStyle() + ";rotation:315");
  22. }
  23. } else if (obj instanceof HWPFDocument) {
  24. }
  25. }
  26. }

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

  1. /**
  2. * Creates a new header of the specified type, to which the
  3. * supplied (and previously unattached!) paragraphs are
  4. * added to.
  5. */
  6. public XWPFHeader createHeader(Enum type, XWPFParagraph[] pars) {
  7. XWPFHeader header = getHeader(type);
  8. if (header == null) {
  9. HdrDocument hdrDoc = HdrDocument.Factory.newInstance();
  10. XWPFRelation relation = XWPFRelation.HEADER;
  11. int i = getRelationIndex(relation);
  12. XWPFHeader wrapper = (XWPFHeader) doc.createRelationship(relation,
  13. XWPFFactory.getInstance(), i);
  14. wrapper.setXWPFDocument(doc);
  15. CTHdrFtr hdr = buildHdr(type, wrapper, pars);
  16. wrapper.setHeaderFooter(hdr);
  17. hdrDoc.setHdr(hdr);
  18. assignHeader(wrapper, type);
  19. header = wrapper;
  20. }
  21. return header;
  22. }

相关文章