Search in sources :

Example 6 with TcPr

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

the class Docx4jUtils method setCellColor.

private void setCellColor(Tc tableCell, String color) {
    if (color != null) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        CTShd shd = new CTShd();
        shd.setFill(color);
        tableCellProperties.setShd(shd);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) CTShd(org.docx4j.wml.CTShd)

Example 7 with TcPr

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

the class NestedTable method main.

public static void main(String[] args) throws Exception {
    System.out.println("Creating package..");
    wordMLPackage = WordprocessingMLPackage.createPackage();
    Tbl tblCredProg = factory.createTbl();
    TblPr tblPr = new TblPr();
    TblStyle tblStyle = new TblStyle();
    tblStyle.setVal("TableGrid");
    tblPr.setTblStyle(tblStyle);
    tblCredProg.setTblPr(tblPr);
    TblWidth width = new TblWidth();
    width.setType("auto");
    width.setW(new BigInteger("0"));
    tblPr.setTblW(width);
    // create row 1
    Tr tr = factory.createTr();
    // col 1 of row 1
    addTc(tr, "A");
    // col 2 of row 1
    addTc(tr, "B");
    tblCredProg.getEGContentRowContent().add(tr);
    // create row 2
    Tr tr2 = factory.createTr();
    TrPr pr = new TrPr();
    tr2.setTrPr(pr);
    // col 1 of row 2
    Tc tc1 = factory.createTc();
    TcPr tcPr = new TcPr();
    TblWidth widtha = new TblWidth();
    widtha.setType("auto");
    widtha.setW(new BigInteger("0"));
    tcPr.setTcW(widtha);
    tc1.setTcPr(tcPr);
    tc1.getEGBlockLevelElts().add(XmlUtils.unmarshalString(tblXML));
    // The following is important or you may get a corrupted docx file
    tc1.getEGBlockLevelElts().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(""));
    tr2.getEGContentCellContent().add(tc1);
    tblCredProg.getEGContentRowContent().add(tr2);
    // col2 of row 2
    addTc(tr2, "C");
    wordMLPackage.getMainDocumentPart().addObject(tblCredProg);
    // Now save it
    wordMLPackage.save(new java.io.File("output/NestedTable.docx"));
    System.out.println("Done.");
}
Also used : TblWidth(org.docx4j.wml.TblWidth) TcPr(org.docx4j.wml.TcPr) TrPr(org.docx4j.wml.TrPr) BigInteger(java.math.BigInteger) TblStyle(org.docx4j.wml.CTTblPrBase.TblStyle) TblPr(org.docx4j.wml.TblPr) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) Tc(org.docx4j.wml.Tc)

Example 8 with TcPr

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

the class Docx4J_例子2 method createNormalCell.

public void createNormalCell(ObjectFactory factory, Tr tr, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor, boolean isHMerger, String mergeVal) {
    Tc tableCell = factory.createTc();
    P p = factory.createP();
    setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    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);
    if (isHMerger) {
        HMerge merge = new HMerge();
        if (mergeVal != null) {
            merge.setVal(mergeVal);
        }
        tcPr.setHMerge(merge);
    } else {
        VMerge merge = new VMerge();
        if (mergeVal != null) {
            merge.setVal(mergeVal);
        }
        tcPr.setVMerge(merge);
    }
    run.getContent().add(t);
    p.getContent().add(run);
    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);
    tr.getContent().add(tableCell);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) TcPr(org.docx4j.wml.TcPr) HMerge(org.docx4j.wml.TcPrInner.HMerge) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Tc(org.docx4j.wml.Tc) VMerge(org.docx4j.wml.TcPrInner.VMerge)

Example 9 with TcPr

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

the class Docx4jStyle_S3 method setCellColor.

public void setCellColor(Tc tableCell, String color) {
    if (color != null) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        CTShd shd = new CTShd();
        shd.setFill(color);
        tableCellProperties.setShd(shd);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) CTShd(org.docx4j.wml.CTShd)

Example 10 with TcPr

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

the class Docx4jStyle_S3 method setCellBorders.

public void setCellBorders(Tc tableCell, boolean borderTop, boolean borderRight, boolean borderBottom, boolean borderLeft) {
    TcPr tableCellProperties = tableCell.getTcPr();
    if (tableCellProperties == null) {
        tableCellProperties = new TcPr();
        tableCell.setTcPr(tableCellProperties);
    }
    CTBorder border = new CTBorder();
    // border.setColor("auto");
    border.setColor("0000FF");
    border.setSz(new BigInteger("20"));
    border.setSpace(new BigInteger("0"));
    border.setVal(STBorder.SINGLE);
    TcBorders borders = new TcBorders();
    if (borderBottom) {
        borders.setBottom(border);
    }
    if (borderTop) {
        borders.setTop(border);
    }
    if (borderLeft) {
        borders.setLeft(border);
    }
    if (borderRight) {
        borders.setRight(border);
    }
    tableCellProperties.setTcBorders(borders);
}
Also used : TcPr(org.docx4j.wml.TcPr) CTBorder(org.docx4j.wml.CTBorder) BigInteger(java.math.BigInteger) TcBorders(org.docx4j.wml.TcPrInner.TcBorders)

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