use of org.docx4j.wml.TcPr 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");
}
}
}
use of org.docx4j.wml.TcPr 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);
}
}
}
use of org.docx4j.wml.TcPr in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setTcVAlign.
/**
* @Description: 设置单元格垂直对齐方式
*/
public void setTcVAlign(Tc tc, STVerticalJc vAlignType) {
if (vAlignType != null) {
TcPr tcPr = getTcPr(tc);
CTVerticalJc vAlign = new CTVerticalJc();
vAlign.setVal(vAlignType);
tcPr.setVAlign(vAlign);
}
}
use of org.docx4j.wml.TcPr 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");
}
}
}
use of org.docx4j.wml.TcPr in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method getTcPr.
public TcPr getTcPr(Tc tc) {
TcPr tcPr = tc.getTcPr();
if (tcPr == null) {
tcPr = new TcPr();
tc.setTcPr(tcPr);
}
return tcPr;
}
Aggregations