List of usage examples for org.apache.poi.xwpf.model XWPFHeaderFooterPolicy createHeader
public XWPFHeader createHeader(Enum type)
From source file:modificarcabeceradocs.appModificacionDOCs.java
private void modificarDOCs(File pathsDocumento) throws FileNotFoundException, IOException { XWPFDocument doc = new XWPFDocument(); XWPFHeaderFooterPolicy policy = doc.getHeaderFooterPolicy(); if (policy.getDefaultHeader() == null && policy.getFirstPageHeader() == null && policy.getDefaultFooter() == null) { // Need to create some new headers // The easy way, gives a single empty paragraph XWPFHeader headerD = policy.createHeader(policy.DEFAULT); //headerD.getParagraphs().createRun().setText("Hello Header World!"); headerD.getParagraphArray(0).createRun().setText("AAAAAAAAAAAAA"); // Or the full control way CTP ctP1 = CTP.Factory.newInstance(); CTR ctR1 = ctP1.addNewR();//from w w w .j a v a 2s.c om CTText t = ctR1.addNewT(); t.setStringValue("Paragraph in header"); XWPFParagraph p1 = new XWPFParagraph(ctP1, doc); XWPFParagraph[] pars = new XWPFParagraph[1]; pars[0] = p1; policy.createHeader(policy.FIRST, pars); doc.write(new FileOutputStream(new File("prueba.docx"))); System.out.println("Cabecera terminada"); } else { // Already has a header, change it } }
From source file:offishell.word.Word.java
License:MIT License
/** * <p>//from ww w.ja va 2 s . co m * Create header with the specified text. * </p> * * @param headerText A header text. */ public Word header(String headerText) { try { CTSectPr section = calculated.getDocument().getBody().addNewSectPr(); XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(calculated, section); XWPFHeader header = policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT); XWPFParagraph para = header.createParagraph(); XWPFRun run = para.createRun(); run.setText(headerText); styles().base().apply(run); } catch (Exception e) { throw I.quiet(e); } return this; }