Example usage for org.apache.poi.xwpf.usermodel XWPFTableCell getCTTc

List of usage examples for org.apache.poi.xwpf.usermodel XWPFTableCell getCTTc

Introduction

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

Prototype

@Internal
    public CTTc getCTTc() 

Source Link

Usage

From source file:de.knowwe.include.export.TableExporter.java

License:Open Source License

@Override
public void export(Section<WikiTable> section, DocumentBuilder manager) throws ExportException {
    // initialize table for easier access
    Matrix<Section<TableCell>> matrix = toMatrix(section);

    // create table with correct dimension
    XWPFDocument doc = manager.getDocument();
    XWPFTable table = doc.createTable(matrix.getRowSize(), matrix.getColSize());
    boolean headerCellsOnly = true;

    for (int row = 0; row < matrix.getRowSize(); row++) {
        XWPFTableRow tableRow = table.getRow(row);
        for (int col = 0; col < matrix.getColSize(); col++) {
            Section<TableCell> cell = matrix.get(row, col);
            boolean isHeader = cell.get().isHeader(cell);
            boolean isZebra = row % 2 == 0;
            headerCellsOnly &= isHeader;

            // prepare cell shading
            XWPFTableCell tableCell = tableRow.getCell(col);
            CTShd shade = tableCell.getCTTc().addNewTcPr().addNewShd();
            if (isHeader) {
                shade.setFill("D0D0D0");
                tableCell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
            } else if (isZebra) {
                shade.setFill("F2F2F2");
            }/*www . j  a v  a 2 s  . c om*/

            // fill cell contents
            DocumentBuilder cellBuilder = new CellBuilder(manager, tableCell, isHeader);
            Section<?> content = Sections.successor(cell, ParagraphTypeForLists.class);
            if (content != null) {
                cellBuilder.export(content);
            }

            // clean trailing white-spaces of each cell
            List<CTR> runs = cellBuilder.getParagraph().getCTP().getRList();
            if (runs.isEmpty())
                continue;
            CTR ctr = runs.get(runs.size() - 1);
            List<CTText> texts = ctr.getTList();
            if (texts.isEmpty())
                continue;
            CTText ctText = texts.get(texts.size() - 1);
            ctText.setStringValue(Strings.trimRight(ctText.getStringValue()));
        }
        // check if the first row(s) have only headers,
        // repeat those headers until a non-header cell has come
        if (headerCellsOnly) {
            tableRow.setRepeatHeader(true);
        }
        tableRow.setCantSplitRow(true);
    }

    // append empty line after each table
    manager.closeParagraph();
    manager.append("\n\r");
    manager.closeParagraph();
}

From source file:edu.gatech.pmase.capstone.awesome.impl.output.DisasterResponseTradeStudyOutputer.java

License:Open Source License

/**
 * Creates an options weighting table for the provided option.
 *
 * @param option the option to create the table for
 * @param table the table to create the option in
 *///from  w w  w.  j a v  a  2  s  .  co  m
private void createOptionWeightingTable(final AbstractArchitectureOption option, final XWPFTable table) {
    LOGGER.debug("Adding architeacture option weighting table for option: " + option.getLabel());
    for (final ArchitectureOptionAttribute attr : option.getPrioritizationAttributess()) {
        LOGGER.debug("Adding architeacture option weighting value: " + attr.getLabel()
                + " with priority value: " + Double.toString(attr.getPriority()));
        LOGGER.debug(attr.toString());

        final XWPFTableRow row = table.createRow();

        final XWPFTableCell attrLabel = row.getCell(0);
        attrLabel.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
        attrLabel.setText(attr.getLabel() + " (" + attr.getUnits() + ")");

        final XWPFTableCell attrWeighting = row.getCell(1);
        attrWeighting.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
        attrWeighting.setText(weightingFormat.format(attr.getPriority() * 100.00) + "%");
        final CTTcPr pr = attrWeighting.getCTTc().addNewTcPr();
        final CTVerticalJc alng = pr.addNewVAlign();
        alng.setVal(STVerticalJc.BOTH);
    }
}

From source file:export.TableFunctionalReq.java

protected static void createReqFuncTable(XWPFDocument doc, FunctionalRequirement funcReq) {

    int[] cols = { 2943, 6507 };

    XWPFTable rf = doc.createTable(9, 2);

    // Get a list of the rows in the table
    List<XWPFTableRow> rows = rf.getRows();
    int rowCt = 0;
    int colCt = 0;

    for (XWPFTableRow row : rows) {

        // get the cells in this row
        List<XWPFTableCell> cells = row.getTableCells();
        for (XWPFTableCell cell : cells) {
            // get a table cell properties element (tcPr)
            CTTcPr tcpr = cell.getCTTc().addNewTcPr();

            // create cell color element
            CTShd ctshd = tcpr.addNewShd();

            ctshd.setColor("auto");
            ctshd.setVal(STShd.CLEAR);/*from   w  w w .ja  v a2s. c  o  m*/

            if (colCt == 0) {
                ctshd.setFill("5C7F92");
            }

            // get 1st paragraph in cell's paragraph list
            XWPFParagraph para = cell.getParagraphs().get(0);
            para.setStyle("AltranNormal");
            para.setSpacingAfter(120);
            para.setSpacingBefore(120);

            // create a run to contain the content
            XWPFRun rh = para.createRun();
            //rh.setFontSize(11);

            rh.setFontFamily("Lucida Sans Unicode");

            if (colCt == 0) {
                rh.setColor("FFFFFF");
            }

            if (rowCt == 0 && colCt == 0) {
                rh.setText("RF " + ((x < 9) ? "0" + x : x) + "- F");
                x++;
            } else if (rowCt == 1 && colCt == 0) {
                rh.setText("Use Case (se disponvel):");
            } else if (rowCt == 2 && colCt == 0) {
                rh.setText("Descrio:");
            } else if (rowCt == 3 && colCt == 0) {
                rh.setText("Fonte:");
            } else if (rowCt == 4 && colCt == 0) {
                rh.setText("Fundamento:");
            } else if (rowCt == 5 && colCt == 0) {
                rh.setText("Critrio de avaliao:");
            } else if (rowCt == 6 && colCt == 0) {
                rh.setText("Satisfao do cliente:");
            } else if (rowCt == 7 && colCt == 0) {
                rh.setText("Insatisfao do cliente:");
            } else if (rowCt == 8 && colCt == 0) {
                rh.setText("Histrico:");
            }

            if (rowCt == 0 && colCt == 1) {// Nome do requisito
                rh.setText(funcReq.getName());
                rh.setBold(true);
            } else if (rowCt == 1 && colCt == 1) { // UseCases
                String testUC = "";
                int cntUC = 0;
                for (UseCase uc : funcReq.getUseCaseCollection()) {

                    if (cntUC == 0) {
                        testUC = uc.getName();
                    } else {
                        testUC = testUC + ", " + uc.getName();
                    }
                    cntUC++;
                }

                rh.setText(testUC);
            } else if (rowCt == 2 && colCt == 1) {// Descrio
                rh.setText(funcReq.getDescription());
            } else if (rowCt == 3 && colCt == 1) {// Fonte
                rh.setText(funcReq.getSource());
            } else if (rowCt == 4 && colCt == 1) {// Fundamento
                rh.setText(funcReq.getReason());
            } else if (rowCt == 5 && colCt == 1) {// Criterio de Avalicao
                rh.setText(funcReq.getAvaliationCriteria());
            } else if (rowCt == 6 && colCt == 1) {// Prioridade
                rh.setText(funcReq.getClientPriority().toString());
            } else if (rowCt == 7 && colCt == 1) {// Insatisfao
                rh.setText(funcReq.getClientInsatisfaction().toString());
            } else if (rowCt == 8 && colCt == 1) {// Historico
                rh.setText("Histrico");
            }

            cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[colCt]));
            colCt++;
        }
        colCt = 0;
        rowCt++;

    }

    doc.createParagraph().createRun().addBreak();

}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.table.cell.AbstractTableCellValueProvider.java

License:Open Source License

public CTTcPr getTcPr(XWPFTableCell cell) {
    CTTc tc = cell.getCTTc();
    if (tc == null) {
        return null;
    }//from w  w w. ja  v a 2s .  c o m
    return tc.getTcPr();
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableInfo.java

License:Open Source License

private int getCellIndex(int cellIndex, XWPFTableCell cell) {
    BigInteger gridSpan = stylesDocument.getTableCellGridSpan(cell.getCTTc().getTcPr());
    if (gridSpan != null) {
        cellIndex = cellIndex + gridSpan.intValue();
    } else {// w  w w. ja va 2 s .c  o  m
        cellIndex++;
    }
    return cellIndex;
}

From source file:fr.opensagres.poi.xwpf.converter.core.utils.XWPFTableUtil.java

License:Open Source License

public static CTDecimalNumber getGridSpan(XWPFTableCell cell) {
    if (cell.getCTTc().getTcPr() != null)
        return cell.getCTTc().getTcPr().getGridSpan();

    return null;//from  w  ww  .j av a  2  s.com
}

From source file:fr.opensagres.poi.xwpf.converter.core.utils.XWPFTableUtil.java

License:Open Source License

public static CTTblWidth getWidth(XWPFTableCell cell) {
    return cell.getCTTc().getTcPr().getTcW();
}

From source file:fr.opensagres.poi.xwpf.converter.core.utils.XWPFTableUtil.java

License:Open Source License

public static TableWidth getTableWidth(XWPFTableCell cell) {
    float width = 0;
    boolean percentUnit = false;
    CTTcPr tblPr = cell.getCTTc().getTcPr();
    if (tblPr.isSetTcW()) {
        CTTblWidth tblWidth = tblPr.getTcW();
        return getTableWidth(tblWidth);
    }/* w ww  . jav a  2s.co  m*/
    return new TableWidth(width, percentUnit);
}

From source file:fr.opensagres.poi.xwpf.converter.xhtml.internal.XHTMLMapper.java

License:Open Source License

@Override
protected Object startVisitTableCell(XWPFTableCell cell, Object tableContainer, boolean firstRow,
        boolean lastRow, boolean firstCell, boolean lastCell, List<XWPFTableCell> vMergeCells)
        throws Exception {
    // 1) create attributes
    // 1.1) Create class attributes.
    XWPFTableRow row = cell.getTableRow();
    XWPFTable table = row.getTable();/*  w w w . j av a 2s .c  o m*/
    AttributesImpl attributes = createClassAttribute(table.getStyleID());

    // 1.2) Create "style" attributes.
    CTTcPr tcPr = cell.getCTTc().getTcPr();
    CSSStyle cssStyle = getStylesDocument().createCSSStyle(tcPr);
    //At lease support solid borders for now
    if (cssStyle != null) {
        TableCellBorder border = getStylesDocument().getTableBorder(table, BorderSide.TOP);
        if (border != null) {
            String style = border.getBorderSize() + "px solid "
                    + StringUtils.toHexString(border.getBorderColor());
            cssStyle.addProperty(CSSStylePropertyConstants.BORDER_TOP, style);
        }

        border = getStylesDocument().getTableBorder(table, BorderSide.BOTTOM);
        if (border != null) {
            String style = border.getBorderSize() + "px solid "
                    + StringUtils.toHexString(border.getBorderColor());
            cssStyle.addProperty(CSSStylePropertyConstants.BORDER_BOTTOM, style);
        }

        border = getStylesDocument().getTableBorder(table, BorderSide.LEFT);
        if (border != null) {
            String style = border.getBorderSize() + "px solid "
                    + StringUtils.toHexString(border.getBorderColor());
            cssStyle.addProperty(CSSStylePropertyConstants.BORDER_LEFT, style);
        }

        border = getStylesDocument().getTableBorder(table, BorderSide.RIGHT);
        if (border != null) {
            String style = border.getBorderSize() + "px solid "
                    + StringUtils.toHexString(border.getBorderColor());
            cssStyle.addProperty(CSSStylePropertyConstants.BORDER_RIGHT, style);
        }
    }
    attributes = createStyleAttribute(cssStyle, attributes);

    // colspan attribute
    BigInteger gridSpan = stylesDocument.getTableCellGridSpan(cell);
    if (gridSpan != null) {
        attributes = SAXHelper.addAttrValue(attributes, COLSPAN_ATTR, gridSpan.intValue());
    }

    if (vMergeCells != null) {
        attributes = SAXHelper.addAttrValue(attributes, ROWSPAN_ATTR, vMergeCells.size());
    }

    // 2) create element
    startElement(TD_ELEMENT, attributes);

    return null;
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>//w  w w.  j  a v a2  s  . c om
 * Helper method to clone {@link XWPFTableCell}.
 * </p>
 * 
 * @param in
 * @param out
 * @param converter
 */
public static void copy(XWPFTableCell in, XWPFTableCell out, UnaryOperator<String> converter) {
    // copy context
    CTTc outCTTc = out.getCTTc();
    CTTcPr outPR = outCTTc.isSetTcPr() ? outCTTc.getTcPr() : outCTTc.addNewTcPr();
    outPR.set(in.getCTTc().getTcPr());

    // clear all elements from out cell
    for (int i = out.getParagraphs().size() - 1; 0 <= i; i--) {
        out.removeParagraph(i);
    }

    // copy children
    for (XWPFParagraph inPara : in.getParagraphs()) {
        copy(inPara, out.addParagraph(), converter);
    }
}