Search in sources :

Example 1 with VMerge

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

the class ComplexTable method addTcVMerge.

private static void addTcVMerge(Tr tr, String label, String text, String vMergeVal, 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);
    VMerge merge = new VMerge();
    if (vMergeVal != null) {
        merge.setVal(vMergeVal);
    }
    tcPr.setVMerge(merge);
    tc.setTcPr(tcPr);
    if (text != null) {
        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) VMerge(org.docx4j.wml.TcPrInner.VMerge)

Example 2 with VMerge

use of org.docx4j.wml.TcPrInner.VMerge 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 3 with VMerge

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

the class Docx4jStyle_S3 method setCellVMerge.

public void setCellVMerge(Tc tableCell, String mergeVal) {
    if (mergeVal != null) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        VMerge merge = new VMerge();
        if (!"close".equals(mergeVal)) {
            merge.setVal(mergeVal);
        }
        tableCellProperties.setVMerge(merge);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) VMerge(org.docx4j.wml.TcPrInner.VMerge)

Example 4 with VMerge

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

the class Docx4j_工具类_S3_Test method mergeCellsVertically.

/**
 * @Description: 跨行合并
 */
public void mergeCellsVertically(Tbl tbl, int col, int fromRow, int toRow) {
    if (col < 0 || fromRow < 0 || toRow < 0) {
        return;
    }
    for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
        Tc tc = getTc(tbl, rowIndex, col);
        if (tc == null) {
            break;
        }
        TcPr tcPr = getTcPr(tc);
        VMerge vMerge = tcPr.getVMerge();
        if (vMerge == null) {
            vMerge = new VMerge();
            tcPr.setVMerge(vMerge);
        }
        if (rowIndex == fromRow) {
            vMerge.setVal("restart");
        } else {
            vMerge.setVal("continue");
        }
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) Tc(org.docx4j.wml.Tc) VMerge(org.docx4j.wml.TcPrInner.VMerge)

Example 5 with VMerge

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

the class WordprocessingMLPackageRender method addMergedCell.

/**
 *  我们创建一个单元格和单元格属性对象.
 *  也创建了一个纵向合并对象. 如果合并值不为null, 将它设置到合并对象中. 然后将该对象添加到
 *  单元格属性并将属性添加到单元格中. 最后设置单元格内容并将单元格添加到行中.
 *  如果合并值为'restart', 表明要开始一个新行. 如果为null, 继续按前面的行处理, 也就是合并单元格.
 */
public void addMergedCell(Tr row, String content, String vMergeVal) {
    Tc tableCell = factory.createTc();
    TcPr tableCellProperties = new TcPr();
    VMerge merge = new VMerge();
    if (vMergeVal != null) {
        merge.setVal(vMergeVal);
    }
    tableCellProperties.setVMerge(merge);
    tableCell.setTcPr(tableCellProperties);
    if (content != null) {
        tableCell.getContent().add(wmlPackage.getMainDocumentPart().createParagraphOfText(content));
    }
    row.getContent().add(tableCell);
}
Also used : TcPr(org.docx4j.wml.TcPr) Tc(org.docx4j.wml.Tc) VMerge(org.docx4j.wml.TcPrInner.VMerge)

Aggregations

TcPr (org.docx4j.wml.TcPr)10 VMerge (org.docx4j.wml.TcPrInner.VMerge)10 Tc (org.docx4j.wml.Tc)7 TblWidth (org.docx4j.wml.TblWidth)2 BigInteger (java.math.BigInteger)1 CTShd (org.docx4j.wml.CTShd)1 CTVerticalJc (org.docx4j.wml.CTVerticalJc)1 P (org.docx4j.wml.P)1 R (org.docx4j.wml.R)1 GridSpan (org.docx4j.wml.TcPrInner.GridSpan)1 HMerge (org.docx4j.wml.TcPrInner.HMerge)1 Text (org.docx4j.wml.Text)1