use of org.docx4j.wml.TcPrInner.GridSpan in project docx4j-template by vindell.
the class Docx4jStyle_S3 method setCellHMerge.
public void setCellHMerge(Tc tableCell, int horizontalMergedCells) {
if (horizontalMergedCells > 1) {
TcPr tableCellProperties = tableCell.getTcPr();
if (tableCellProperties == null) {
tableCellProperties = new TcPr();
tableCell.setTcPr(tableCellProperties);
}
GridSpan gridSpan = new GridSpan();
gridSpan.setVal(new BigInteger(String.valueOf(horizontalMergedCells)));
tableCellProperties.setGridSpan(gridSpan);
tableCell.setTcPr(tableCellProperties);
}
}
use of org.docx4j.wml.TcPrInner.GridSpan in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method getTcByPosition.
/**
* 实现思路:
* 主要分在当前行上方插入行和在当前行下方插入行。对首尾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;
}
use of org.docx4j.wml.TcPrInner.GridSpan 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;
}
use of org.docx4j.wml.TcPrInner.GridSpan 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;
}
Aggregations