Search in sources :

Example 11 with TblWidth

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

the class ComplexTable method addTc.

private static void addTc(Tr tr, String label, String text, String width) {
    Tc tc = factory.createTc();
    TcPr tcPr = new TcPr();
    TblWidth tblwidth = new TblWidth();
    tblwidth.setType("dxa");
    tblwidth.setW(new BigInteger(width));
    tcPr.setTcW(tblwidth);
    tc.setTcPr(tcPr);
    tc.getEGBlockLevelElts().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(text));
    tr.getEGContentCellContent().add(tc);
}
Also used : TblWidth(org.docx4j.wml.TblWidth) TcPr(org.docx4j.wml.TcPr) BigInteger(java.math.BigInteger) Tc(org.docx4j.wml.Tc)

Example 12 with TblWidth

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

the class NestedTable method addTc.

protected static void addTc(Tr tr, String text) {
    Tc tc = factory.createTc();
    TcPr tcPr = new TcPr();
    TblWidth width = new TblWidth();
    width.setType("dxa");
    width.setW(new BigInteger("3192"));
    tcPr.setTcW(width);
    tc.setTcPr(tcPr);
    tc.getEGBlockLevelElts().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(text));
    tr.getEGContentCellContent().add(tc);
}
Also used : TblWidth(org.docx4j.wml.TblWidth) TcPr(org.docx4j.wml.TcPr) BigInteger(java.math.BigInteger) Tc(org.docx4j.wml.Tc)

Example 13 with TblWidth

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

the class Docx4J_例子2 method setTableGridCol.

// 设置整列宽度
/**
 * @param tableWidthPercent
 *            表格占页面宽度百分比
 * @param widthPercent
 *            各列百分比
 */
public void setTableGridCol(WordprocessingMLPackage wordPackage, ObjectFactory factory, Tbl table, double tableWidthPercent, double[] widthPercent) throws Exception {
    int width = getWritableWidth(wordPackage);
    int tableWidth = (int) (width * tableWidthPercent / 100);
    TblGrid tblGrid = factory.createTblGrid();
    for (int i = 0; i < widthPercent.length; i++) {
        TblGridCol gridCol = factory.createTblGridCol();
        gridCol.setW(BigInteger.valueOf((long) (tableWidth * widthPercent[i] / 100)));
        tblGrid.getGridCol().add(gridCol);
    }
    table.setTblGrid(tblGrid);
    TblPr tblPr = table.getTblPr();
    if (tblPr == null) {
        tblPr = factory.createTblPr();
    }
    TblWidth tblWidth = new TblWidth();
    // 这一行是必须的,不自己设置宽度默认是auto
    tblWidth.setType("dxa");
    tblWidth.setW(new BigInteger(tableWidth + ""));
    tblPr.setTblW(tblWidth);
    table.setTblPr(tblPr);
}
Also used : TblWidth(org.docx4j.wml.TblWidth) BigInteger(java.math.BigInteger) TblPr(org.docx4j.wml.TblPr) STHint(org.docx4j.wml.STHint) TblGrid(org.docx4j.wml.TblGrid) TblGridCol(org.docx4j.wml.TblGridCol)

Example 14 with TblWidth

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

the class Docx4J_简单例子2 method setTableGridCol.

// 设置整列宽度
public void setTableGridCol(WordprocessingMLPackage wordPackage, ObjectFactory factory, Tbl table, double[] widthPercent) throws Exception {
    int width = getWritableWidth(wordPackage);
    TblGrid tblGrid = factory.createTblGrid();
    for (int i = 0; i < widthPercent.length; i++) {
        TblGridCol gridCol = factory.createTblGridCol();
        gridCol.setW(BigInteger.valueOf((long) (width * widthPercent[i] / 100)));
        tblGrid.getGridCol().add(gridCol);
    }
    table.setTblGrid(tblGrid);
    TblPr tblPr = table.getTblPr();
    if (tblPr == null) {
        tblPr = factory.createTblPr();
    }
    TblWidth tblWidth = new TblWidth();
    // 这一行是必须的,不自己设置宽度默认是auto
    tblWidth.setType("dxa");
    tblWidth.setW(new BigInteger("" + width));
    tblPr.setTblW(tblWidth);
    table.setTblPr(tblPr);
}
Also used : TblWidth(org.docx4j.wml.TblWidth) BigInteger(java.math.BigInteger) TblPr(org.docx4j.wml.TblPr) STHint(org.docx4j.wml.STHint) TblGrid(org.docx4j.wml.TblGrid) TblGridCol(org.docx4j.wml.TblGridCol)

Example 15 with TblWidth

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

the class Docx4jStyle_S3 method setCellMargins.

public void setCellMargins(Tc tableCell, int top, int right, int bottom, int left) {
    TcPr tableCellProperties = tableCell.getTcPr();
    if (tableCellProperties == null) {
        tableCellProperties = new TcPr();
        tableCell.setTcPr(tableCellProperties);
    }
    TcMar margins = new TcMar();
    if (bottom > 0) {
        TblWidth bW = new TblWidth();
        bW.setType("dxa");
        bW.setW(BigInteger.valueOf(bottom));
        margins.setBottom(bW);
    }
    if (top > 0) {
        TblWidth tW = new TblWidth();
        tW.setType("dxa");
        tW.setW(BigInteger.valueOf(top));
        margins.setTop(tW);
    }
    if (left > 0) {
        TblWidth lW = new TblWidth();
        lW.setType("dxa");
        lW.setW(BigInteger.valueOf(left));
        margins.setLeft(lW);
    }
    if (right > 0) {
        TblWidth rW = new TblWidth();
        rW.setType("dxa");
        rW.setW(BigInteger.valueOf(right));
        margins.setRight(rW);
    }
    tableCellProperties.setTcMar(margins);
}
Also used : TcMar(org.docx4j.wml.TcMar) TblWidth(org.docx4j.wml.TblWidth) TcPr(org.docx4j.wml.TcPr)

Aggregations

TblWidth (org.docx4j.wml.TblWidth)20 TcPr (org.docx4j.wml.TcPr)14 BigInteger (java.math.BigInteger)10 TblPr (org.docx4j.wml.TblPr)8 Tc (org.docx4j.wml.Tc)7 Tbl (org.docx4j.wml.Tbl)5 Tr (org.docx4j.wml.Tr)4 TblGrid (org.docx4j.wml.TblGrid)3 TblGridCol (org.docx4j.wml.TblGridCol)3 TblStyle (org.docx4j.wml.CTTblPrBase.TblStyle)2 STHint (org.docx4j.wml.STHint)2 TcMar (org.docx4j.wml.TcMar)2 GridSpan (org.docx4j.wml.TcPrInner.GridSpan)2 VMerge (org.docx4j.wml.TcPrInner.VMerge)2 TrPr (org.docx4j.wml.TrPr)2 File (java.io.File)1 CTTblCellMar (org.docx4j.wml.CTTblCellMar)1 CTVerticalJc (org.docx4j.wml.CTVerticalJc)1 Jc (org.docx4j.wml.Jc)1 ObjectFactory (org.docx4j.wml.ObjectFactory)1