diff options
author | Mark Murphy <jmarkmurphy@apache.org> | 2016-10-13 01:13:45 +0000 |
---|---|---|
committer | Mark Murphy <jmarkmurphy@apache.org> | 2016-10-13 01:13:45 +0000 |
commit | 37f1598ac2989fef0be17d65a7e0407802380f7a (patch) | |
tree | 2bd39a6657527ab971a8ec13273f862c3d00b603 /src/examples | |
parent | 740932ee85c1d465933ebfd306bcc4bc5795f070 (diff) | |
download | poi-37f1598ac2989fef0be17d65a7e0407802380f7a.tar.gz poi-37f1598ac2989fef0be17d65a7e0407802380f7a.zip |
53009: Problem creating header and footer
Task-Url: https://bz.apache.org/bugzilla/show_bug.cgi?id=53009
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1764563 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocumentWithHeader.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocumentWithHeader.java b/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocumentWithHeader.java new file mode 100644 index 0000000000..7595b5b499 --- /dev/null +++ b/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocumentWithHeader.java @@ -0,0 +1,60 @@ +package org.apache.poi.xwpf.usermodel; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFRun; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; + +/** + * + * @author Richard Ngo + * + */ +public class SimpleDocumentWithHeader { + + private static XWPFParagraph[] pars; + + public static void main(String[] args) { + XWPFDocument doc = new XWPFDocument(); + + XWPFParagraph p = doc.createParagraph(); + + XWPFRun r = p.createRun(); + r.setText("Some Text"); + r.setBold(true); + r = p.createRun(); + r.setText("Goodbye"); + + CTP ctP = CTP.Factory.newInstance(); + CTText t = ctP.addNewR().addNewT(); + t.setStringValue("header"); + pars = new XWPFParagraph[1]; + p = new XWPFParagraph(ctP, doc); + pars[0] = p; + + XWPFHeaderFooterPolicy hfPolicy = doc.createHeaderFooterPolicy(); + hfPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, pars); + + ctP = CTP.Factory.newInstance(); + t = ctP.addNewR().addNewT(); + t.setStringValue("My Footer"); + pars[0] = new XWPFParagraph(ctP, doc); + hfPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, pars); + + try { + OutputStream os = new FileOutputStream(new File("header.docx")); + doc.write(os); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +}
\ No newline at end of file |