Search in sources :

Example 31 with TcPr

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

the class Docx4J_简单例子 method addTableCell.

// 新增单元格
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) {
    Tc tableCell = factory.createTc();
    P p = factory.createP();
    setParagraphAlign(factory, p, jcEnumeration);
    Text t = factory.createText();
    t.setValue(content);
    R run = factory.createR();
    // 设置表格内容字体样式
    run.setRPr(rpr);
    run.getContent().add(t);
    p.getContent().add(run);
    tableCell.getContent().add(p);
    if (hasBgColor) {
        TcPr tcPr = tableCell.getTcPr();
        if (tcPr == null) {
            tcPr = factory.createTcPr();
        }
        CTShd shd = tcPr.getShd();
        if (shd == null) {
            shd = factory.createCTShd();
        }
        shd.setColor("auto");
        shd.setFill(backgroudColor);
        tcPr.setShd(shd);
        tableCell.setTcPr(tcPr);
    }
    tableRow.getContent().add(tableCell);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) TcPr(org.docx4j.wml.TcPr) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) Tc(org.docx4j.wml.Tc)

Example 32 with TcPr

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

the class Docx4J_简单例子2 method addTableCell.

// 新增单元格
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) {
    Tc tableCell = factory.createTc();
    P p = factory.createP();
    setParagraphAlign(factory, p, jcEnumeration);
    Text t = factory.createText();
    t.setValue(content);
    R run = factory.createR();
    // 设置表格内容字体样式
    run.setRPr(rpr);
    TcPr tcPr = tableCell.getTcPr();
    if (tcPr == null) {
        tcPr = factory.createTcPr();
    }
    CTVerticalJc valign = factory.createCTVerticalJc();
    valign.setVal(STVerticalJc.CENTER);
    tcPr.setVAlign(valign);
    run.getContent().add(t);
    p.getContent().add(run);
    PPr ppr = p.getPPr();
    if (ppr == null) {
        ppr = factory.createPPr();
    }
    // 设置段后距离
    Spacing spacing = new Spacing();
    spacing.setAfter(new BigInteger("0"));
    spacing.setLineRule(STLineSpacingRule.AUTO);
    ppr.setSpacing(spacing);
    p.setPPr(ppr);
    tableCell.getContent().add(p);
    if (hasBgColor) {
        CTShd shd = tcPr.getShd();
        if (shd == null) {
            shd = factory.createCTShd();
        }
        shd.setColor("auto");
        shd.setFill(backgroudColor);
        tcPr.setShd(shd);
        tableCell.setTcPr(tcPr);
    }
    tableRow.getContent().add(tableCell);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) TcPr(org.docx4j.wml.TcPr) BigInteger(java.math.BigInteger) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) Spacing(org.docx4j.wml.PPrBase.Spacing) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Tc(org.docx4j.wml.Tc)

Example 33 with TcPr

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

Example 34 with TcPr

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

the class Docx4jStyle_S3 method setCellHMerge.

public void setCellHMerge(Tc tableCell, int horizontalMergedCells) {
    if (horizontalMergedCells > 1) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        GridSpan gridSpan = new GridSpan();
        gridSpan.setVal(new BigInteger(String.valueOf(horizontalMergedCells)));
        tableCellProperties.setGridSpan(gridSpan);
        tableCell.setTcPr(tableCellProperties);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) BigInteger(java.math.BigInteger) GridSpan(org.docx4j.wml.TcPrInner.GridSpan)

Example 35 with TcPr

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

the class Docx4jStyle_S3 method setVerticalAlignment.

public void setVerticalAlignment(Tc tableCell, STVerticalJc align) {
    if (align != null) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        CTVerticalJc valign = new CTVerticalJc();
        valign.setVal(align);
        tableCellProperties.setVAlign(valign);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) CTVerticalJc(org.docx4j.wml.CTVerticalJc)

Aggregations

TcPr (org.docx4j.wml.TcPr)46 Tc (org.docx4j.wml.Tc)22 TblWidth (org.docx4j.wml.TblWidth)14 BigInteger (java.math.BigInteger)11 VMerge (org.docx4j.wml.TcPrInner.VMerge)10 GridSpan (org.docx4j.wml.TcPrInner.GridSpan)9 CTVerticalJc (org.docx4j.wml.CTVerticalJc)7 Tr (org.docx4j.wml.Tr)7 CTShd (org.docx4j.wml.CTShd)6 P (org.docx4j.wml.P)5 R (org.docx4j.wml.R)5 Text (org.docx4j.wml.Text)4 Tbl (org.docx4j.wml.Tbl)3 TblPr (org.docx4j.wml.TblPr)3 HMerge (org.docx4j.wml.TcPrInner.HMerge)3 BooleanDefaultTrue (org.docx4j.wml.BooleanDefaultTrue)2 CTBorder (org.docx4j.wml.CTBorder)2 TblStyle (org.docx4j.wml.CTTblPrBase.TblStyle)2 PPr (org.docx4j.wml.PPr)2 TcMar (org.docx4j.wml.TcMar)2