Search in sources :

Example 11 with TcPr

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

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

the class Docx4jStyle_S3 method setCellWidth.

public void setCellWidth(Tc tableCell, int width) {
    if (width > 0) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        TblWidth tableWidth = new TblWidth();
        tableWidth.setType("dxa");
        tableWidth.setW(BigInteger.valueOf(width));
        tableCellProperties.setTcW(tableWidth);
    }
}
Also used : TblWidth(org.docx4j.wml.TblWidth) TcPr(org.docx4j.wml.TcPr)

Example 13 with TcPr

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

the class Docx4jStyle_S3 method setCellNoWrap.

public void setCellNoWrap(Tc tableCell) {
    TcPr tableCellProperties = tableCell.getTcPr();
    if (tableCellProperties == null) {
        tableCellProperties = new TcPr();
        tableCell.setTcPr(tableCellProperties);
    }
    BooleanDefaultTrue b = new BooleanDefaultTrue();
    b.setVal(true);
    tableCellProperties.setNoWrap(b);
}
Also used : TcPr(org.docx4j.wml.TcPr) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Example 14 with TcPr

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

the class Docx4j_合并单元格_S4_Test method mergeCellsHorizontalByGridSpan.

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 15 with TcPr

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

the class Docx4j_合并单元格_S4_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)

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