Search in sources :

Example 36 with Tr

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

the class DocxElementWmlRender method newTable.

public Tbl newTable(int row, int cell) {
    // 创建表格对象
    Tbl table = factory.createTbl();
    for (int i = 0; i < row; i++) {
        Tr tableRow = factory.createTr();
        for (int j = 0; j < cell; j++) {
            newCell(tableRow, "");
        }
        table.getContent().add(tableRow);
    }
    return table;
}
Also used : Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl)

Example 37 with Tr

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

the class DocxElementWmlRender method newRow.

public Tr newRow(Tbl table, int row) {
    Tr tbRow = factory.createTr();
    table.getContent().set(row, tbRow);
    return tbRow;
}
Also used : Tr(org.docx4j.wml.Tr)

Example 38 with Tr

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

the class Docx4j_工具类_S3_Test method getTblContentList.

/**
 * @Description: 获取表格内容
 */
public List<String> getTblContentList(Tbl tbl) throws Exception {
    List<String> resultList = new ArrayList<String>();
    List<Tr> trList = getTblAllTr(tbl);
    for (Tr tr : trList) {
        StringBuffer sb = new StringBuffer();
        List<Tc> tcList = getTrAllCell(tr);
        for (Tc tc : tcList) {
            sb.append(getElementContent(tc) + ",");
        }
        resultList.add(sb.toString());
    }
    return resultList;
}
Also used : ArrayList(java.util.ArrayList) Tr(org.docx4j.wml.Tr) Tc(org.docx4j.wml.Tc)

Example 39 with Tr

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

the class SettingColumnWidthForTable method main.

/**
 *  创建一个带边框的表格并添加一行. 然后添加两个带内容的单元格并给定宽度.
 */
public static void main(String[] args) throws Docx4JException {
    wordMLPackage = WordprocessingMLPackage.createPackage();
    factory = Context.getWmlObjectFactory();
    Tbl table = factory.createTbl();
    addBorders(table);
    Tr tr = factory.createTr();
    addTableCellWithWidth(tr, "Field 1", 2500);
    addTableCellWithWidth(tr, "Field 2", 0);
    table.getContent().add(tr);
    wordMLPackage.getMainDocumentPart().addObject(table);
    wordMLPackage.save(new java.io.File("src/main/HelloWord133.docx"));
}
Also used : Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl)

Aggregations

Tr (org.docx4j.wml.Tr)39 Tbl (org.docx4j.wml.Tbl)23 Tc (org.docx4j.wml.Tc)17 P (org.docx4j.wml.P)10 TblPr (org.docx4j.wml.TblPr)7 TcPr (org.docx4j.wml.TcPr)7 File (java.io.File)6 R (org.docx4j.wml.R)6 RPr (org.docx4j.wml.RPr)6 ArrayList (java.util.ArrayList)5 STHint (org.docx4j.wml.STHint)5 BigInteger (java.math.BigInteger)4 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)4 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)4 TblStyle (org.docx4j.wml.CTTblPrBase.TblStyle)4 TblWidth (org.docx4j.wml.TblWidth)4 Text (org.docx4j.wml.Text)4 ObjectFactory (org.docx4j.wml.ObjectFactory)3 TblGrid (org.docx4j.wml.TblGrid)3 TblGridCol (org.docx4j.wml.TblGridCol)3