Search in sources :

Example 16 with TcPr

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

the class Docx4j_工具类_S3_Test method mergeCellsHorizontal.

/**
 * @Description: 跨列合并
 */
public void mergeCellsHorizontal(Tbl tbl, int row, int fromCell, int toCell) {
    if (row < 0 || fromCell < 0 || toCell < 0) {
        return;
    }
    List<Tr> trList = getTblAllTr(tbl);
    if (row > trList.size()) {
        return;
    }
    Tr tr = trList.get(row);
    List<Tc> tcList = getTrAllCell(tr);
    for (int cellIndex = fromCell, len = Math.min(tcList.size() - 1, toCell); cellIndex <= len; cellIndex++) {
        Tc tc = tcList.get(cellIndex);
        TcPr tcPr = getTcPr(tc);
        HMerge hMerge = tcPr.getHMerge();
        if (hMerge == null) {
            hMerge = new HMerge();
            tcPr.setHMerge(hMerge);
        }
        if (cellIndex == fromCell) {
            hMerge.setVal("restart");
        } else {
            hMerge.setVal("continue");
        }
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) HMerge(org.docx4j.wml.TcPrInner.HMerge) Tr(org.docx4j.wml.Tr) Tc(org.docx4j.wml.Tc)

Example 17 with TcPr

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

the class Docx4j_工具类_S3_Test method mergeCellsHorizontalByGridSpan.

/*------------------------------------Word 表格相关---------------------------------------------------  */
/**
 * @Description: 跨列合并
 */
public void mergeCellsHorizontalByGridSpan(Tbl tbl, int row, int fromCell, int toCell) {
    if (row < 0 || fromCell < 0 || toCell < 0) {
        return;
    }
    List<Tr> trList = getTblAllTr(tbl);
    if (row > trList.size()) {
        return;
    }
    Tr tr = trList.get(row);
    List<Tc> tcList = getTrAllCell(tr);
    for (int cellIndex = Math.min(tcList.size() - 1, toCell); cellIndex >= fromCell; cellIndex--) {
        Tc tc = tcList.get(cellIndex);
        TcPr tcPr = getTcPr(tc);
        if (cellIndex == fromCell) {
            GridSpan gridSpan = tcPr.getGridSpan();
            if (gridSpan == null) {
                gridSpan = new GridSpan();
                tcPr.setGridSpan(gridSpan);
            }
            gridSpan.setVal(BigInteger.valueOf(Math.min(tcList.size() - 1, toCell) - fromCell + 1));
        } else {
            tr.getContent().remove(cellIndex);
        }
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) Tr(org.docx4j.wml.Tr) Tc(org.docx4j.wml.Tc) GridSpan(org.docx4j.wml.TcPrInner.GridSpan)

Example 18 with TcPr

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

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

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

the class Docx4j_工具类_S3_Test method getTcPr.

public TcPr getTcPr(Tc tc) {
    TcPr tcPr = tc.getTcPr();
    if (tcPr == null) {
        tcPr = new TcPr();
        tc.setTcPr(tcPr);
    }
    return tcPr;
}
Also used : TcPr(org.docx4j.wml.TcPr)

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