Search in sources :

Example 26 with Tr

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

the class Docx4J_简单例子 method createNormalTableTest.

public void createNormalTableTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
    RPr titleRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false);
    RPr contentRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
    Tbl table = factory.createTbl();
    addBorders(table, "2");
    Tr titleRow = factory.createTr();
    addTableCell(factory, wordMLPackage, titleRow, "序号", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "姓甚", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "名谁", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "籍贯", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "营生", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    table.getContent().add(titleRow);
    for (int i = 0; i < 10; i++) {
        Tr contentRow = factory.createTr();
        addTableCell(factory, wordMLPackage, contentRow, i + "", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "无名氏", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "佚名", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "武林", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "吟诗赋曲", contentRpr, JcEnumeration.CENTER, false, null);
        table.getContent().add(contentRow);
    }
    setTableAlign(factory, table, JcEnumeration.CENTER);
    t.addObject(table);
}
Also used : RPr(org.docx4j.wml.RPr) Tr(org.docx4j.wml.Tr) STHint(org.docx4j.wml.STHint) Tbl(org.docx4j.wml.Tbl)

Example 27 with Tr

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

the class Docx4J_简单例子2 method createNormalTableTest.

public void createNormalTableTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
    RPr titleRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false);
    RPr contentRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
    Tbl table = factory.createTbl();
    addBorders(table, "2");
    // 百分比
    double[] widthPercent = new double[] { 15, 20, 20, 20, 25 };
    setTableGridCol(wordMLPackage, factory, table, widthPercent);
    Tr titleRow = factory.createTr();
    setTableTrHeight(factory, titleRow, "500");
    addTableCell(factory, wordMLPackage, titleRow, "序号", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "姓甚", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "名谁", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "籍贯", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    addTableCell(factory, wordMLPackage, titleRow, "营生", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
    table.getContent().add(titleRow);
    for (int i = 0; i < 10; i++) {
        Tr contentRow = factory.createTr();
        addTableCell(factory, wordMLPackage, contentRow, i + "", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "无名氏", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "佚名", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "武林", contentRpr, JcEnumeration.CENTER, false, null);
        addTableCell(factory, wordMLPackage, contentRow, "吟诗赋曲", contentRpr, JcEnumeration.CENTER, false, null);
        table.getContent().add(contentRow);
    }
    setTableAlign(factory, table, JcEnumeration.CENTER);
    t.addObject(table);
}
Also used : RPr(org.docx4j.wml.RPr) Tr(org.docx4j.wml.Tr) STHint(org.docx4j.wml.STHint) Tbl(org.docx4j.wml.Tbl)

Example 28 with Tr

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

the class Docx4j_Helper method name.

public static void name() throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    String titleStr = "测试插入段落";
    P p = Docx4j_Helper.factory.createP();
    String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>";
    RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr);
    setParagraphContent(p, rpr, titleStr);
    documentPart.getContent().add(5, p);
    String tblPrStr = "<w:tblPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:tblW w:w=\"8522\" w:type=\"dxa\"/><w:tblBorders><w:top w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:left w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:bottom w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:right w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:insideH w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/></w:tblBorders></w:tblPr>";
    Tbl tbl = Docx4j_Helper.factory.createTbl();
    TblPr tblPr = (TblPr) XmlUtils.unmarshalString(tblPrStr);
    tbl.setTblPr(tblPr);
    Tr tr = Docx4j_Helper.factory.createTr();
    Tc tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tbl.getContent().add(tr);
    tr = Docx4j_Helper.factory.createTr();
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tbl.getContent().add(tr);
    documentPart.getContent().add(9, tbl);
// Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);
}
Also used : P(org.docx4j.wml.P) RPr(org.docx4j.wml.RPr) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) TblPr(org.docx4j.wml.TblPr) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) Tc(org.docx4j.wml.Tc)

Example 29 with Tr

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

the class Docx4jStyle_S3 method createTableWithContent.

public Tbl createTableWithContent(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, String imgFilePath) throws Exception {
    Tbl table = factory.createTbl();
    // for TEST: this adds borders to all cells
    TblPr tblPr = new TblPr();
    TblStyle tblStyle = new TblStyle();
    tblStyle.setVal("TableGrid");
    tblPr.setTblStyle(tblStyle);
    table.setTblPr(tblPr);
    Tr tableRow = factory.createTr();
    // a default table cell style
    Docx4jStyle_S3 defStyle = new Docx4jStyle_S3();
    defStyle.setBold(false);
    defStyle.setItalic(false);
    defStyle.setUnderline(false);
    defStyle.setHorizAlignment(JcEnumeration.CENTER);
    // a specific table cell style
    Docx4jStyle_S3 style = new Docx4jStyle_S3();
    style.setBold(true);
    style.setItalic(true);
    style.setUnderline(true);
    style.setFontSize("40");
    style.setFontColor("FF0000");
    style.setCnFontFamily("微软雅黑");
    style.setEnFontFamily("Times New Roman");
    style.setTop(300);
    style.setBackground("CCFFCC");
    style.setVerticalAlignment(STVerticalJc.CENTER);
    style.setHorizAlignment(JcEnumeration.CENTER);
    style.setBorderTop(true);
    style.setBorderBottom(true);
    style.setNoWrap(true);
    addTableCell(factory, tableRow, "测试Field 1", 3500, style, 1, null);
    // start vertical merge for Filed 2 and Field 3 on 3 rows
    addTableCell(factory, tableRow, "测试Field 2", 3500, defStyle, 1, "restart");
    addTableCell(factory, tableRow, "测试Field 3", 1500, defStyle, 1, "restart");
    table.getContent().add(tableRow);
    tableRow = factory.createTr();
    addTableCell(factory, tableRow, "Text", 3500, defStyle, 1, null);
    addTableCell(factory, tableRow, "", 3500, defStyle, 1, "");
    addTableCell(factory, tableRow, "", 1500, defStyle, 1, "");
    table.getContent().add(tableRow);
    tableRow = factory.createTr();
    addTableCell(factory, tableRow, "Interval", 3500, defStyle, 1, null);
    addTableCell(factory, tableRow, "", 3500, defStyle, 1, "close");
    addTableCell(factory, tableRow, "", 1500, defStyle, 1, "close");
    table.getContent().add(tableRow);
    // add an image horizontally merged on 3 cells
    String filenameHint = null;
    String altText = null;
    int id1 = 0;
    int id2 = 1;
    byte[] bytes = getImageBytes(imgFilePath);
    P pImage;
    try {
        pImage = newImage(wordMLPackage, factory, bytes, filenameHint, altText, id1, id2, 8500);
        tableRow = factory.createTr();
        addTableCell(factory, tableRow, pImage, 8500, defStyle, 3, null);
        table.getContent().add(tableRow);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return table;
}
Also used : P(org.docx4j.wml.P) TblStyle(org.docx4j.wml.CTTblPrBase.TblStyle) TblPr(org.docx4j.wml.TblPr) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl)

Example 30 with Tr

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

the class Docx4j_合并单元格_S4_Test method getTblAllTr.

/**
 * @Description: 得到表格所有的行
 */
public List<Tr> getTblAllTr(Tbl tbl) {
    List<Object> objList = getAllElementFromObject(tbl, Tr.class);
    List<Tr> trList = new ArrayList<Tr>();
    if (objList == null) {
        return trList;
    }
    for (Object obj : objList) {
        if (obj instanceof Tr) {
            Tr tr = (Tr) obj;
            trList.add(tr);
        }
    }
    return trList;
}
Also used : ArrayList(java.util.ArrayList) Tr(org.docx4j.wml.Tr)

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