Search in sources :

Example 1 with CTVerticalJc

use of org.docx4j.wml.CTVerticalJc 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 2 with CTVerticalJc

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

the class Docx4j_工具类_S3_Test method setDocVAlign.

/**
 * @Description:设置word 垂直对齐方式(Word默认方式都是"顶端对齐")
 */
public void setDocVAlign(WordprocessingMLPackage wordPackage, STVerticalJc valignType) {
    if (valignType != null) {
        SectPr sectPr = getDocSectPr(wordPackage);
        CTVerticalJc valign = sectPr.getVAlign();
        if (valign == null) {
            valign = new CTVerticalJc();
            sectPr.setVAlign(valign);
        }
        valign.setVal(valignType);
    }
}
Also used : SectPr(org.docx4j.wml.SectPr) CTVerticalJc(org.docx4j.wml.CTVerticalJc)

Example 3 with CTVerticalJc

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

the class Docx4j_工具类_S3_Test method setTcVAlign.

/**
 * @Description: 设置单元格垂直对齐方式
 */
public void setTcVAlign(Tc tc, STVerticalJc vAlignType) {
    if (vAlignType != null) {
        TcPr tcPr = getTcPr(tc);
        CTVerticalJc vAlign = new CTVerticalJc();
        vAlign.setVal(vAlignType);
        tcPr.setVAlign(vAlign);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) CTVerticalJc(org.docx4j.wml.CTVerticalJc)

Example 4 with CTVerticalJc

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

the class Docx4jUtils method setVerticalAlignment.

private 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)

Example 5 with CTVerticalJc

use of org.docx4j.wml.CTVerticalJc 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();
    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);
    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);
    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) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Tc(org.docx4j.wml.Tc)

Aggregations

CTVerticalJc (org.docx4j.wml.CTVerticalJc)7 TcPr (org.docx4j.wml.TcPr)6 CTShd (org.docx4j.wml.CTShd)3 P (org.docx4j.wml.P)3 R (org.docx4j.wml.R)3 Tc (org.docx4j.wml.Tc)3 Text (org.docx4j.wml.Text)3 BigInteger (java.math.BigInteger)1 PPr (org.docx4j.wml.PPr)1 Spacing (org.docx4j.wml.PPrBase.Spacing)1 SectPr (org.docx4j.wml.SectPr)1 HMerge (org.docx4j.wml.TcPrInner.HMerge)1 VMerge (org.docx4j.wml.TcPrInner.VMerge)1