Example usage for org.apache.poi.xwpf.model XWPFHeaderFooterPolicy createHeader

List of usage examples for org.apache.poi.xwpf.model XWPFHeaderFooterPolicy createHeader

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.model XWPFHeaderFooterPolicy createHeader.

Prototype

public XWPFHeader createHeader(Enum type, XWPFParagraph[] pars) 

Source Link

Document

Creates a new header of the specified type, to which the supplied (and previously unattached!) paragraphs are added to.

Usage

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

/**
 * Header title//from w w w  .ja v  a  2 s .co m
 * 
 * @param document
 * @param text
 * @throws IOException
 */
public void pageHeader(XWPFDocument document, String text) throws IOException {
    CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
    XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
    CTP ctpHeader = CTP.Factory.newInstance();
    CTR ctrHeader = ctpHeader.addNewR();
    CTText ctHeader = ctrHeader.addNewT();
    ctHeader.setStringValue(text);
    XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, document);
    headerParagraph.setAlignment(ParagraphAlignment.RIGHT);
    XWPFParagraph[] parsHeader = new XWPFParagraph[1];
    parsHeader[0] = headerParagraph;
    policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader);
}