Search in sources :

Example 11 with TblPr

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

the class TableWithStyledContent method addBorders.

/**
 *  本方法给表格添加边框
 */
private static void addBorders(Tbl table) {
    table.setTblPr(new TblPr());
    CTBorder border = new CTBorder();
    border.setColor("auto");
    border.setSz(new BigInteger("4"));
    border.setSpace(new BigInteger("0"));
    border.setVal(STBorder.SINGLE);
    TblBorders borders = new TblBorders();
    borders.setBottom(border);
    borders.setLeft(border);
    borders.setRight(border);
    borders.setTop(border);
    borders.setInsideH(border);
    borders.setInsideV(border);
    table.getTblPr().setTblBorders(borders);
}
Also used : CTBorder(org.docx4j.wml.CTBorder) BigInteger(java.math.BigInteger) TblBorders(org.docx4j.wml.TblBorders) TblPr(org.docx4j.wml.TblPr)

Example 12 with TblPr

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

the class AddingAnInlineImageToTable method addBorders.

/**
 * 给表格添加简单的黑色边框.
 * @param table
 */
private static void addBorders(Tbl table) {
    table.setTblPr(new TblPr());
    CTBorder border = BorderUtils.ctBorder();
    TblBorders borders = BorderUtils.tblBorders(border);
    table.getTblPr().setTblBorders(borders);
}
Also used : CTBorder(org.docx4j.wml.CTBorder) TblBorders(org.docx4j.wml.TblBorders) TblPr(org.docx4j.wml.TblPr)

Example 13 with TblPr

use of org.docx4j.wml.TblPr 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)

Example 14 with TblPr

use of org.docx4j.wml.TblPr in project Java-Tutorial by gpcodervn.

the class Docx4jUtils method createTableWithContent.

/**
 * Our createTableWithContent method follows (we use dxa values). There are 4
 * rows, some cells with vertical merge, and some with horizontal merge.
 */
private Tbl createTableWithContent() {
    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
    DocxStyle defStyle = new DocxStyle();
    defStyle.setBold(false);
    defStyle.setItalic(false);
    defStyle.setUnderline(false);
    defStyle.setHorizAlignment(JcEnumeration.CENTER);
    // a specific table cell style
    DocxStyle style = new DocxStyle();
    style.setBold(true);
    style.setItalic(true);
    style.setUnderline(true);
    style.setFontSize("40");
    style.setFontColor("FF0000");
    style.setFontFamily("Book Antiqua");
    style.setTop(300);
    style.setBackground("CCFFCC");
    style.setVerticalAlignment(STVerticalJc.CENTER);
    style.setHorizAlignment(JcEnumeration.CENTER);
    style.setBorderTop(true);
    style.setBorderBottom(true);
    style.setNoWrap(true);
    addTableCell(tableRow, "Field 1", 3500, style, 1, null);
    // start vertical merge for Filed 2 and Field 3 on 3 rows
    addTableCell(tableRow, "Field 2", 3500, defStyle, 1, "restart");
    addTableCell(tableRow, "Field 3", 1500, defStyle, 1, "restart");
    table.getContent().add(tableRow);
    tableRow = factory.createTr();
    addTableCell(tableRow, "Text", 3500, defStyle, 1, null);
    addTableCell(tableRow, "", 3500, defStyle, 1, "");
    addTableCell(tableRow, "", 1500, defStyle, 1, "");
    table.getContent().add(tableRow);
    tableRow = factory.createTr();
    addTableCell(tableRow, "Interval", 3500, defStyle, 1, null);
    addTableCell(tableRow, "", 3500, defStyle, 1, "close");
    addTableCell(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;
    try {
        bytes = getImageBytes(new File("/resources/image.png"));
        P pImage = newImage(wordMLPackage, bytes, filenameHint, altText, id1, id2, 8500);
        tableRow = factory.createTr();
        addTableCell(tableRow, pImage, 8500, defStyle, 3, null);
        table.getContent().add(tableRow);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return table;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) TblStyle(org.docx4j.wml.CTTblPrBase.TblStyle) IOException(java.io.IOException) TblPr(org.docx4j.wml.TblPr) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) P(org.docx4j.wml.P) File(java.io.File) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl)

Example 15 with TblPr

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

the class Docx4J_例子2 method setTableAlign.

// 表格水平对齐方式
public void setTableAlign(ObjectFactory factory, Tbl table, JcEnumeration jcEnumeration) {
    TblPr tablePr = table.getTblPr();
    if (tablePr == null) {
        tablePr = factory.createTblPr();
    }
    Jc jc = tablePr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    tablePr.setJc(jc);
    table.setTblPr(tablePr);
}
Also used : STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) TblPr(org.docx4j.wml.TblPr)

Aggregations

TblPr (org.docx4j.wml.TblPr)26 BigInteger (java.math.BigInteger)14 TblBorders (org.docx4j.wml.TblBorders)10 CTBorder (org.docx4j.wml.CTBorder)9 TblWidth (org.docx4j.wml.TblWidth)8 Tbl (org.docx4j.wml.Tbl)7 Tr (org.docx4j.wml.Tr)7 Jc (org.docx4j.wml.Jc)5 Tc (org.docx4j.wml.Tc)5 TblStyle (org.docx4j.wml.CTTblPrBase.TblStyle)4 CTVerticalJc (org.docx4j.wml.CTVerticalJc)4 P (org.docx4j.wml.P)4 STVerticalJc (org.docx4j.wml.STVerticalJc)4 TblGrid (org.docx4j.wml.TblGrid)3 TblGridCol (org.docx4j.wml.TblGridCol)3 TcPr (org.docx4j.wml.TcPr)3 File (java.io.File)2 STHint (org.docx4j.wml.STHint)2 TrPr (org.docx4j.wml.TrPr)2 FileNotFoundException (java.io.FileNotFoundException)1