Search in sources :

Example 46 with Tc

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

the class Docx4j_工具类_S3_Test method getTcCellSizeWithMergeNum.

/**
 * @Description: 得到行的列数
 */
public int getTcCellSizeWithMergeNum(Tr tr) {
    int cellSize = 1;
    List<Tc> tcList = getTrAllCell(tr);
    if (tcList == null || tcList.size() == 0) {
        return cellSize;
    }
    cellSize = tcList.size();
    for (Tc tc : tcList) {
        TcPr tcPr = getTcPr(tc);
        GridSpan gridSpan = tcPr.getGridSpan();
        if (gridSpan != null) {
            cellSize += gridSpan.getVal().intValue() - 1;
        }
    }
    return cellSize;
}
Also used : TcPr(org.docx4j.wml.TcPr) Tc(org.docx4j.wml.Tc) GridSpan(org.docx4j.wml.TcPrInner.GridSpan)

Example 47 with Tc

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

the class Docx4j_工具类_S3_Test method getTblContentList.

/**
 * @Description: 获取表格内容
 */
public List<String> getTblContentList(Tbl tbl) throws Exception {
    List<String> resultList = new ArrayList<String>();
    List<Tr> trList = getTblAllTr(tbl);
    for (Tr tr : trList) {
        StringBuffer sb = new StringBuffer();
        List<Tc> tcList = getTrAllCell(tr);
        for (Tc tc : tcList) {
            sb.append(getElementContent(tc) + ",");
        }
        resultList.add(sb.toString());
    }
    return resultList;
}
Also used : ArrayList(java.util.ArrayList) Tr(org.docx4j.wml.Tr) Tc(org.docx4j.wml.Tc)

Example 48 with Tc

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

the class Docx4j_替换模板 method mergeCellsVertically.

/**
 * @Description: 跨行合并
 */
public static 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 = factory.createTcPrInnerVMerge();
            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 49 with Tc

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

the class Docx4j_替换模板 method replaceTrTotalData.

/**
 * 替换表格合计数据
 */
private void replaceTrTotalData(Tr tr, String[] dataArr) {
    List<Object> tcObjList = tr.getContent();
    Tc tc = null;
    // 跳过合计
    for (int i = 2, len = tcObjList.size(); i < len; i++) {
        tc = (Tc) XmlUtils.unwrap(tcObjList.get(i));
        replaceTcContent(tc, dataArr[i - 2]);
    }
}
Also used : Tc(org.docx4j.wml.Tc)

Example 50 with Tc

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

the class Docx4j_替换模板 method getTrAllCell.

public static List<Tc> getTrAllCell(Tr tr) {
    List<Object> objList = getAllElementFromObject(tr, Tc.class);
    List<Tc> tcList = new ArrayList<Tc>();
    if (objList == null) {
        return tcList;
    }
    for (Object tcObj : objList) {
        if (tcObj instanceof Tc) {
            Tc objTc = (Tc) tcObj;
            tcList.add(objTc);
        }
    }
    return tcList;
}
Also used : ArrayList(java.util.ArrayList) Tc(org.docx4j.wml.Tc)

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