Search in sources :

Example 41 with TcPr

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

the class WmlElementUtils method getTcByPosition.

/*
     * http://53873039oycg.iteye.com/blog/2194849
     *  实现思路:
        主要分在当前行上方插入行和在当前行下方插入行。对首尾2行特殊处理,在有跨行合并情况时,在第一行上面或者在最后一行下面插入是不会跨行的但是可能会跨列。
       对于中间的行,主要参照当前行,如果当前行跨行,则新增行也跨行,如果当前行单元格结束跨行,则新增的上方插入行跨行,下方插入行不跨行,如果当前行单元格开始跨行,则新增的上方插入行不跨行,下发插入行跨行。
       主要思路就是这样,插入的时候需要得到真实位置的单元格,代码如下:
       
     */
// 按位置得到单元格(考虑跨列合并情况)
public Tc getTcByPosition(List<Tc> tcList, int position) {
    int k = 0;
    for (int i = 0, len = tcList.size(); i < len; i++) {
        Tc tc = tcList.get(i);
        TcPr trPr = tc.getTcPr();
        if (trPr != null) {
            GridSpan gridSpan = trPr.getGridSpan();
            if (gridSpan != null) {
                k += gridSpan.getVal().intValue() - 1;
            }
        }
        if (k >= position) {
            return tcList.get(i);
        }
        k++;
    }
    if (position < tcList.size()) {
        return tcList.get(position);
    }
    return null;
}
Also used : TcPr(org.docx4j.wml.TcPr) Tc(org.docx4j.wml.Tc) GridSpan(org.docx4j.wml.TcPrInner.GridSpan)

Example 42 with TcPr

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

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

the class Docx4j_工具类_S3_Test method setTcWidth.

/**
 * @Description: 设置单元格宽度
 */
public void setTcWidth(Tc tc, String width) {
    if (StringUtils.isNotBlank(width)) {
        TcPr tcPr = getTcPr(tc);
        TblWidth tcW = tcPr.getTcW();
        if (tcW == null) {
            tcW = new TblWidth();
            tcPr.setTcW(tcW);
        }
        tcW.setW(new BigInteger(width));
        tcW.setType("dxa");
    }
}
Also used : TblWidth(org.docx4j.wml.TblWidth) TcPr(org.docx4j.wml.TcPr) BigInteger(java.math.BigInteger)

Example 44 with TcPr

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

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

the class SettingColumnWidthForTable method setCellWidth.

/**
 *  本方法创建一个单元格属性集对象和一个表格宽度对象. 将给定的宽度设置到宽度对象然后将其添加到
 *  属性集对象. 最后将属性集对象设置到单元格中.
 */
private static void setCellWidth(Tc tableCell, int width) {
    TcPr tableCellProperties = new TcPr();
    TblWidth tableWidth = new TblWidth();
    tableWidth.setW(BigInteger.valueOf(width));
    tableCellProperties.setTcW(tableWidth);
    tableCell.setTcPr(tableCellProperties);
}
Also used : TblWidth(org.docx4j.wml.TblWidth) 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