Example usage for org.apache.poi.hwpf.usermodel Section getTable

List of usage examples for org.apache.poi.hwpf.usermodel Section getTable

Introduction

In this page you can find the example usage for org.apache.poi.hwpf.usermodel Section getTable.

Prototype

public Table getTable(Paragraph paragraph) 

Source Link

Document

Gets the table that starts with paragraph.

Usage

From source file:org.docx4j.convert.in.Doc.java

License:Apache License

/**
 * This method is private, since the fact that conversion is (currently)
 * performed using POI's HWPF should be encapsulated.
 * //  w  w w.j a  v a  2 s .  c  om
 * @param doc
 * @param wordMLPackage
 * @return success or failure
 */
private static void convert(HWPFDocument doc, WordprocessingMLPackage wordMLPackage) throws Exception {

    // Convert styles
    org.apache.poi.hwpf.model.StyleSheet stylesheet = doc.getStyleSheet();
    // TODO - higher priority
    // At present, a default set of styles are defined in the output
    // document.

    // Convert lists
    org.apache.poi.hwpf.model.ListTables listTables = doc.getListTables();
    // TODO

    // Convert document properties
    org.apache.poi.hwpf.model.DocumentProperties docProps = doc.getDocProperties();
    // TODO

    // Convert main document part

    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();

    Range r = doc.getRange();

    for (int x = 0; x < r.numSections(); x++) {
        Section s = r.getSection(x);

        // TODO - convert section

        for (int y = 0; y < s.numParagraphs(); y++) {
            Paragraph p = s.getParagraph(y);

            if (p.isInTable()) {
                Table t = s.getTable(p);
                int cl = numCol(t);

                log.info("Found " + t.numRows() + "x" + cl + " table - TODO - convert");

                handleTable(wordMLPackage, doc, t, stylesheet, documentPart, factory);

                // addTODO(factory, wmlP, "[TABLE " + + t.numRows() + "x" +
                // cl
                // + " - can't convert tables yet]");

                y += t.numParagraphs() - 1;
            }

            else {
                org.docx4j.wml.P paraToAdd = handleP(wordMLPackage, doc, p, stylesheet, documentPart, factory);

                documentPart.addObject(paraToAdd);
            }

        }
    }

}