Example usage for org.apache.poi.xwpf.usermodel XWPFDocument getHeaderList

List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument getHeaderList

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFDocument getHeaderList.

Prototype

public List<XWPFHeader> getHeaderList() 

Source Link

Usage

From source file:biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.java

License:Apache License

public int processBookmarks2Document(XWPFDocument dxProcess, List<IDocumentBookmark> arrBookmarks) {
    // First Prozessing all paragraphs.
    for (XWPFParagraph paraCurrent : dxProcess.getParagraphs()) {
        processBookmarks2Paragraph(arrBookmarks, paraCurrent);
    }/*from w w  w  . j a  v  a 2  s  . c  o m*/

    for (XWPFTable tabCurrent : dxProcess.getTables()) {
        processBookmarks2Table(arrBookmarks, tabCurrent);
    }
    for (XWPFHeader headCurrent : dxProcess.getHeaderList()) {
        for (XWPFParagraph paraCurrent : headCurrent.getParagraphs()) {
            processBookmarks2Paragraph(arrBookmarks, paraCurrent);
        }
        for (XWPFTable tabCurrent : headCurrent.getTables()) {
            processBookmarks2Table(arrBookmarks, tabCurrent);
        }
    }
    for (XWPFFooter footCurrent : dxProcess.getFooterList()) {
        for (XWPFParagraph paraCurrent : footCurrent.getParagraphs()) {
            processBookmarks2Paragraph(arrBookmarks, paraCurrent);
        }
        for (XWPFTable tabCurrent : footCurrent.getTables()) {
            processBookmarks2Table(arrBookmarks, tabCurrent);
        }
    }

    return 1;
}

From source file:ch.admin.isb.hermes5.business.word.Docx4jWordDocumentCustomizerTest.java

License:Apache License

private Map<String, String> getTableMap(byte[] result) throws IOException {
    Map<String, String> map = new HashMap<String, String>();
    XWPFDocument document = new XWPFDocument(new ByteArrayInputStream(result));
    List<XWPFTable> tables = new ArrayList<XWPFTable>();
    tables.addAll(document.getTables());
    List<XWPFHeader> headers = document.getHeaderList();
    for (XWPFHeader header : headers) {
        tables.addAll(header.getTables());
    }/*ww w  . ja  v  a  2  s.  c  om*/
    for (XWPFTable xwpfTable : tables) {
        List<XWPFTableRow> rows = xwpfTable.getRows();
        for (XWPFTableRow xwpfTableRow : rows) {
            List<XWPFTableCell> tableCells = xwpfTableRow.getTableCells();
            if (tableCells.size() == 2) {
                map.put(tableCells.get(0).getText(), tableCells.get(1).getText());
            }
            if (tableCells.size() == 1) {
                map.put(tableCells.get(0).getText(), "");
            }
        }
    }

    return map;
}

From source file:ch.admin.searchreplace.SearchReplaceTerms.java

License:Apache License

/**
 * Ersetzt eine Liste von Ausdruecken in einer Datei und schreibt das Resultat nach Output
 * @param input Inputdatei/*from   w  w w  .j  a  v  a 2 s.c  om*/
 * @param output Outputdatei
 * @param srTerms Begriff
 * @throws IOException I/O Fehler
 * @throws InvalidFormatException OpenXML Document korrupt
 * @throws FileNotFoundException Datei nicht vorhanden
 */
private static void searchReplaceInFile(String input, String output, HashMap<String, String> srTerms)
        throws IOException, InvalidFormatException, FileNotFoundException {
    XWPFDocument doc = new XWPFDocument(OPCPackage.open(input));

    // Header
    List<XWPFHeader> header = doc.getHeaderList();
    for (Iterator<XWPFHeader> e = header.iterator(); e.hasNext();) {
        XWPFHeader h = e.next();
        for (XWPFParagraph p : h.getParagraphs()) {
            XWPFRun r = consolidateRuns(p);
            if (r != null)
                searchReplace(srTerms, r);
        }
        for (XWPFTable tbl : h.getTables())
            for (XWPFTableRow row : tbl.getRows())
                for (XWPFTableCell cell : row.getTableCells())
                    for (XWPFParagraph p : cell.getParagraphs()) {
                        XWPFRun r = consolidateRuns(p);
                        if (r != null)
                            searchReplace(srTerms, r);
                    }
    }

    // Document
    for (XWPFParagraph p : doc.getParagraphs()) {
        XWPFRun r = consolidateRuns(p);
        if (r != null)
            searchReplace(srTerms, r);
    }
    for (XWPFTable tbl : doc.getTables())
        for (XWPFTableRow row : tbl.getRows())
            for (XWPFTableCell cell : row.getTableCells())
                for (XWPFParagraph p : cell.getParagraphs()) {
                    XWPFRun r = consolidateRuns(p);
                    if (r != null)
                        searchReplace(srTerms, r);
                }

    doc.write(new FileOutputStream(output));
}

From source file:com.siemens.sw360.licenseinfo.outputGenerators.DocxUtils.java

License:Open Source License

public static void replaceText(XWPFDocument document, String placeHolder, String replaceText) {
    for (XWPFHeader header : document.getHeaderList())
        replaceAllBodyElements(header.getBodyElements(), placeHolder, replaceText);
    replaceAllBodyElements(document.getBodyElements(), placeHolder, replaceText);
}

From source file:offishell.word.Word.java

License:MIT License

/**
 * <p>/* w w  w .  j  a v  a  2s. co  m*/
 * Replace variable text.
 * </p>
 * 
 * @param doc
 * @param object
 */
private void replace(XWPFDocument doc) {
    // for paragraph
    for (XWPFParagraph para : copy(doc.getParagraphs())) {
        replace(para);
    }

    // for table
    for (XWPFTable table : copy(doc.getTables())) {
        for (XWPFTableRow row : copy(table.getRows())) {
            for (XWPFTableCell cell : copy(row.getTableCells())) {
                for (XWPFParagraph para : copy(cell.getParagraphs())) {
                    replace(para);
                }
            }
        }
    }

    // for header
    for (XWPFHeader header : copy(doc.getHeaderList())) {
        for (XWPFParagraph para : copy(header.getParagraphs())) {
            replace(para);
        }
    }

    // for footer
    for (XWPFFooter footer : copy(doc.getFooterList())) {
        for (XWPFParagraph para : copy(footer.getParagraphs())) {
            replace(para);
        }
    }
}

From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java

License:Open Source License

@Override
public IConstruct caseDocumentTemplate(DocumentTemplate documentTemplate) {
    doSwitch(documentTemplate.getBody());

    final XWPFDocument document = (XWPFDocument) generatedDocument;
    final Iterator<XWPFFooter> footers = document.getFooterList().iterator();
    for (final Template footer : documentTemplate.getFooters()) {
        final XWPFFooter f = footers.next();
        cleanHeaderFooter(f);//w  w  w .ja v  a2  s  .c o m
        generatedDocument = f;
        doSwitch(footer);
    }
    final Iterator<XWPFHeader> headers = document.getHeaderList().iterator();
    for (final Template header : documentTemplate.getHeaders()) {
        final XWPFHeader h = headers.next();
        cleanHeaderFooter(h);
        generatedDocument = h;
        doSwitch(header);
    }

    return null;
}