Search in sources :

Example 1 with ICell

use of org.apache.poi.xwpf.usermodel.ICell in project tika by apache.

the class XWPFWordExtractorDecorator method extractTable.

private void extractTable(XWPFTable table, XWPFListManager listManager, XHTMLContentHandler xhtml) throws SAXException, XmlException, IOException {
    xhtml.startElement("table");
    xhtml.startElement("tbody");
    for (XWPFTableRow row : table.getRows()) {
        xhtml.startElement("tr");
        for (ICell cell : row.getTableICells()) {
            xhtml.startElement("td");
            if (cell instanceof XWPFTableCell) {
                extractIBodyText((XWPFTableCell) cell, listManager, xhtml);
            } else if (cell instanceof XWPFSDTCell) {
                xhtml.characters(((XWPFSDTCell) cell).getContent().getText());
            }
            xhtml.endElement("td");
        }
        xhtml.endElement("tr");
    }
    xhtml.endElement("tbody");
    xhtml.endElement("table");
}
Also used : XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) XWPFSDTCell(org.apache.poi.xwpf.usermodel.XWPFSDTCell) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow) ICell(org.apache.poi.xwpf.usermodel.ICell)

Example 2 with ICell

use of org.apache.poi.xwpf.usermodel.ICell in project poi by apache.

the class XWPFWordExtractor method appendTableText.

private void appendTableText(StringBuffer text, XWPFTable table) {
    //this works recursively to pull embedded tables from tables
    for (XWPFTableRow row : table.getRows()) {
        List<ICell> cells = row.getTableICells();
        for (int i = 0; i < cells.size(); i++) {
            ICell cell = cells.get(i);
            if (cell instanceof XWPFTableCell) {
                text.append(((XWPFTableCell) cell).getTextRecursively());
            } else if (cell instanceof XWPFSDTCell) {
                text.append(((XWPFSDTCell) cell).getContent().getText());
            }
            if (i < cells.size() - 1) {
                text.append("\t");
            }
        }
        text.append('\n');
    }
}
Also used : XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) XWPFSDTCell(org.apache.poi.xwpf.usermodel.XWPFSDTCell) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow) ICell(org.apache.poi.xwpf.usermodel.ICell)

Aggregations

ICell (org.apache.poi.xwpf.usermodel.ICell)2 XWPFSDTCell (org.apache.poi.xwpf.usermodel.XWPFSDTCell)2 XWPFTableCell (org.apache.poi.xwpf.usermodel.XWPFTableCell)2 XWPFTableRow (org.apache.poi.xwpf.usermodel.XWPFTableRow)2