Search in sources :

Example 6 with Tc

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

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

Example 8 with Tc

use of org.docx4j.wml.Tc 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 9 with Tc

use of org.docx4j.wml.Tc 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 10 with Tc

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

Aggregations

Tc (org.docx4j.wml.Tc)53 TcPr (org.docx4j.wml.TcPr)22 Tr (org.docx4j.wml.Tr)17 P (org.docx4j.wml.P)11 R (org.docx4j.wml.R)10 Tbl (org.docx4j.wml.Tbl)9 BigInteger (java.math.BigInteger)7 TblWidth (org.docx4j.wml.TblWidth)7 VMerge (org.docx4j.wml.TcPrInner.VMerge)7 Text (org.docx4j.wml.Text)7 GridSpan (org.docx4j.wml.TcPrInner.GridSpan)6 CTVerticalJc (org.docx4j.wml.CTVerticalJc)5 TblPr (org.docx4j.wml.TblPr)5 ArrayList (java.util.ArrayList)4 CTShd (org.docx4j.wml.CTShd)4 File (java.io.File)3 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)3 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)3 ObjectFactory (org.docx4j.wml.ObjectFactory)3 PPr (org.docx4j.wml.PPr)3