Search in sources :

Example 6 with TrPr

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

the class Docx4j_工具类_S3_Test method setTrHeight.

/**
 * @Description:设置tr高度
 */
public void setTrHeight(Tr tr, String heigth) {
    TrPr trPr = getTrPr(tr);
    CTHeight ctHeight = new CTHeight();
    ctHeight.setVal(new BigInteger(heigth));
    TrHeight trHeight = new TrHeight(ctHeight);
    trHeight.set(trPr);
}
Also used : TrHeight(org.docx4j.model.properties.table.tr.TrHeight) TrPr(org.docx4j.wml.TrPr) BigInteger(java.math.BigInteger) CTHeight(org.docx4j.wml.CTHeight)

Example 7 with TrPr

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

the class Docx4j_替换模板 method replaceTrData.

/**
 * 替换tr数据,其他插入
 */
private void replaceTrData(Tbl tbl, Tr tr, List<String[]> dataList, int trIndex) throws Exception {
    TrPr trPr = XmlUtils.deepCopy(tr.getTrPr());
    String tcContent = null;
    String[] tcMarshaArr = getTcMarshalStr(tr);
    String[] dataArr = null;
    for (int i = 0, iLen = dataList.size(); i < iLen; i++) {
        dataArr = dataList.get(i);
        Tr newTr = null;
        Tc newTc = null;
        if (i == 0) {
            newTr = tr;
        } else {
            newTr = factory.createTr();
            if (trPr != null) {
                newTr.setTrPr(trPr);
            }
            newTc = factory.createTc();
            newTr.getContent().add(newTc);
        }
        for (int j = 0, jLen = dataArr.length; j < jLen; j++) {
            tcContent = tcMarshaArr[j];
            if (tcContent != null) {
                tcContent = tcContent.replaceAll("(<w:t>)(.*?)(</w:t>)", "<w:t>" + dataArr[j] + "</w:t>");
                newTc = (Tc) XmlUtils.unmarshalString(tcContent);
            } else {
                newTc = factory.createTc();
                setNewTcContent(newTc, dataArr[j]);
            }
            // 新增tr
            if (i != 0) {
                newTr.getContent().add(newTc);
            } else {
                // 替换
                newTr.getContent().set(j + 1, newTc);
            }
        }
        if (i != 0) {
            tbl.getContent().add(trIndex + i, newTr);
        }
    }
}
Also used : TrPr(org.docx4j.wml.TrPr) Tr(org.docx4j.wml.Tr) Tc(org.docx4j.wml.Tc)

Aggregations

TrPr (org.docx4j.wml.TrPr)7 BigInteger (java.math.BigInteger)5 TrHeight (org.docx4j.model.properties.table.tr.TrHeight)3 CTHeight (org.docx4j.wml.CTHeight)3 Tc (org.docx4j.wml.Tc)3 Tr (org.docx4j.wml.Tr)3 TblStyle (org.docx4j.wml.CTTblPrBase.TblStyle)2 Tbl (org.docx4j.wml.Tbl)2 TblPr (org.docx4j.wml.TblPr)2 TblWidth (org.docx4j.wml.TblWidth)2 TcPr (org.docx4j.wml.TcPr)2 File (java.io.File)1 GridSpan (org.docx4j.wml.TcPrInner.GridSpan)1