Search in sources :

Example 51 with Tc

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

the class SettingColumnWidthForTable method addTableCellWithWidth.

/**
 *  本方法创建一个单元格并将给定的内容添加进去.
 *  如果给定的宽度大于0, 将这个宽度设置到单元格.
 *  最后, 将单元格添加到行中.
 */
private static void addTableCellWithWidth(Tr row, String content, int width) {
    Tc tableCell = factory.createTc();
    tableCell.getContent().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(content));
    if (width > 0) {
        setCellWidth(tableCell, width);
    }
    row.getContent().add(tableCell);
}
Also used : Tc(org.docx4j.wml.Tc)

Example 52 with Tc

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

the class TableWithBorders 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 53 with Tc

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

the class TableWithMergedCells method addMergedCell.

/**
 *  我们创建一个单元格和单元格属性对象.
 *  也创建了一个纵向合并对象. 如果合并值不为null, 将它设置到合并对象中. 然后将该对象添加到
 *  单元格属性并将属性添加到单元格中. 最后设置单元格内容并将单元格添加到行中.
 *
 *  如果合并值为'restart', 表明要开始一个新行. 如果为null, 继续按前面的行处理, 也就是合并单元格.
 */
private static 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(wordMLPackage.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)

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