Search in sources :

Example 16 with Tc

use of org.docx4j.wml.Tc in project docx4j-template by vindell.

the class WordprocessingMLPackageRender method addMergedCell.

/**
 *  我们创建一个单元格和单元格属性对象.
 *  也创建了一个纵向合并对象. 如果合并值不为null, 将它设置到合并对象中. 然后将该对象添加到
 *  单元格属性并将属性添加到单元格中. 最后设置单元格内容并将单元格添加到行中.
 *  如果合并值为'restart', 表明要开始一个新行. 如果为null, 继续按前面的行处理, 也就是合并单元格.
 */
public void addMergedCell(Tr row, String content, String vMergeVal) {
    Tc tableCell = factory.createTc();
    TcPr tableCellProperties = new TcPr();
    VMerge merge = new VMerge();
    if (vMergeVal != null) {
        merge.setVal(vMergeVal);
    }
    tableCellProperties.setVMerge(merge);
    tableCell.setTcPr(tableCellProperties);
    if (content != null) {
        tableCell.getContent().add(wmlPackage.getMainDocumentPart().createParagraphOfText(content));
    }
    row.getContent().add(tableCell);
}
Also used : TcPr(org.docx4j.wml.TcPr) Tc(org.docx4j.wml.Tc) VMerge(org.docx4j.wml.TcPrInner.VMerge)

Example 17 with Tc

use of org.docx4j.wml.Tc in project docx4j-template by vindell.

the class AddingATable method addTableCell.

private static void addTableCell(Tr tableRow, String content) {
    Tc tableCell = factory.createTc();
    tableCell.getContent().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(content));
    tableRow.getContent().add(tableCell);
}
Also used : Tc(org.docx4j.wml.Tc)

Example 18 with Tc

use of org.docx4j.wml.Tc in project docx4j-template by vindell.

the class DocxElementWmlRender method newCell.

public Tc newCell(Tbl table, int row, String content) {
    Tc tbCell = factory.createTc();
    tbCell.getContent().add(newParagraph(content));
    getRow(table, row).getContent().add(tbCell);
    return tbCell;
}
Also used : Tc(org.docx4j.wml.Tc)

Example 19 with Tc

use of org.docx4j.wml.Tc in project TranskribusCore by Transkribus.

the class DocxBuilder method getDocxTable.

private static Tbl getDocxTable(WordprocessingMLPackage wPMLpackage, boolean isWordBased, int rows, int cols, List<HashMap<Integer, TrpTableCellType>> allRows, int tablesize, MainDocumentPart mdp) throws Exception {
    int writableWidthTwips = wPMLpackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
    int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
    Tbl table = TblFactory.createTable(0, 0, cellWidthTwips);
    TblGrid tblGrid = factory.createTblGrid();
    for (int i = 0; i < cols; i++) {
        TblGridCol col = factory.createTblGridCol();
        col.setW(BigInteger.valueOf(cellWidthTwips));
        tblGrid.getGridCol().add(col);
    }
    table.setTblGrid(tblGrid);
    int i = 0;
    for (HashMap<Integer, TrpTableCellType> entry : allRows) {
        Tr row = factory.createTr();
        table.getContent().add(row);
        i++;
        int d = 0;
        if (entry.keySet().size() != cols) {
            logger.debug("size of entries does not match columns ");
        }
        for (Integer key : entry.keySet()) {
            Tc cell = factory.createTc();
            row.getContent().add(cell);
            String rowSpan = null;
            int colSpan = 1;
            boolean mergedVertical = false;
            int colsize = cellWidthTwips;
            if (entry.get(key) != null) {
                if (entry.get(key).getRowSpan() > 1) {
                    mergedVertical = true;
                    rowSpan = "restart";
                }
                // PageXmlUtils.buildPolygon(entry.get(key).getCoords().getPoints()).getBounds().getMaxX();
                double maxX = entry.get(key).getBoundingBox().getMaxX();
                // PageXmlUtils.buildPolygon(entry.get(key).getCoords().getPoints()).getBounds().getMinX();
                double minX = entry.get(key).getBoundingBox().getMinX();
                double colsizeRel = maxX - minX;
                double colsizetmp = colsizeRel / (double) tablesize;
                // logger.debug("colsizetmp " + colsizetmp);
                colsize = (int) (writableWidthTwips * colsizetmp);
                colSpan = entry.get(key).getColSpan();
                // logger.debug("colsize " + colsize);
                // logger.debug("text in this cell is " + entry.get(key).getUnicodeTextFromLines());
                int colID = entry.get(key).getCol();
                int rowID = entry.get(key).getRow();
            } else {
                // logger.debug("no cell for this column ");
                mergedVertical = true;
            }
            applyGridSpan(cell, colSpan, rowSpan, colsize, mergedVertical);
            P columnPara = factory.createP();
            // P columnPara = (P) column.getContent().get(0);
            cell.getContent().add(columnPara);
            d++;
            Text tx = factory.createText();
            R run = factory.createR();
            if (entry.get(key) != null) {
                // old solution till now: tx.setValue(entry.get(key).getUnicodeTextFromLines());
                if (entry.get(key).getUnicodeTextFromLines() != "") {
                    exportTextRegion(entry.get(key), isWordBased, columnPara, mdp);
                }
            }
            run.getContent().add(tx);
            columnPara.getContent().add(run);
        }
    }
    return table;
}
Also used : TrpTableCellType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTableCellType) Text(org.docx4j.wml.Text) Tc(org.docx4j.wml.Tc) BigInteger(java.math.BigInteger) P(org.docx4j.wml.P) R(org.docx4j.wml.R) TblGrid(org.docx4j.wml.TblGrid) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) TblGridCol(org.docx4j.wml.TblGridCol)

Example 20 with Tc

use of org.docx4j.wml.Tc in project mdw-designer by CenturyLinkCloud.

the class DocxBuilder method addTable.

public Tbl addTable(String[] headers, String[][] values, int fontSize, int indent) {
    ObjectFactory factory = Context.getWmlObjectFactory();
    int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
    int cols = headers.length;
    int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
    Tbl tbl = TblFactory.createTable(0, cols, cellWidthTwips);
    Tr thead = factory.createTr();
    for (int i = 0; i < headers.length; i++) {
        Tc tc = factory.createTc();
        tc.getContent().add(createParagraph(headers[i], fontSize, true));
        thead.getContent().add(tc);
    }
    tbl.getContent().add(0, thead);
    for (int i = 0; i < values[0].length; i++) {
        Tr tr = factory.createTr();
        for (int j = 0; j < headers.length; j++) {
            Tc tc = factory.createTc();
            tc.getContent().add(createParagraph(values[j][i], fontSize, false));
            tr.getContent().add(tc);
        }
        tbl.getContent().add(i + 1, tr);
    }
    getMdp().addObject(tbl);
    if (indent != 0) {
        TblPr tblPr = tbl.getTblPr();
        TblWidth tblIndent = factory.createTblWidth();
        tblIndent.setType("dxa");
        tblIndent.setW(BigInteger.valueOf(indent));
        tblPr.setTblInd(tblIndent);
    }
    return tbl;
}
Also used : ObjectFactory(org.docx4j.wml.ObjectFactory) TblWidth(org.docx4j.wml.TblWidth) TblPr(org.docx4j.wml.TblPr) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) Tc(org.docx4j.wml.Tc)

Aggregations

Tc (org.docx4j.wml.Tc)53 TcPr (org.docx4j.wml.TcPr)22 Tr (org.docx4j.wml.Tr)17 P (org.docx4j.wml.P)11 R (org.docx4j.wml.R)10 Tbl (org.docx4j.wml.Tbl)9 BigInteger (java.math.BigInteger)7 TblWidth (org.docx4j.wml.TblWidth)7 VMerge (org.docx4j.wml.TcPrInner.VMerge)7 Text (org.docx4j.wml.Text)7 GridSpan (org.docx4j.wml.TcPrInner.GridSpan)6 CTVerticalJc (org.docx4j.wml.CTVerticalJc)5 TblPr (org.docx4j.wml.TblPr)5 ArrayList (java.util.ArrayList)4 CTShd (org.docx4j.wml.CTShd)4 File (java.io.File)3 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)3 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)3 ObjectFactory (org.docx4j.wml.ObjectFactory)3 PPr (org.docx4j.wml.PPr)3