use of org.docx4j.wml.STVerticalJc in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method addTrByIndex.
/**
* @Description: 在表格指定位置新增一行(默认按表格定义的列数添加)
*/
public void addTrByIndex(Tbl tbl, int index, STVerticalJc vAlign, JcEnumeration hAlign) {
TblGrid tblGrid = tbl.getTblGrid();
Tr tr = new Tr();
if (tblGrid != null) {
List<TblGridCol> gridList = tblGrid.getGridCol();
for (TblGridCol tblGridCol : gridList) {
Tc tc = new Tc();
setTcWidth(tc, tblGridCol.getW().toString());
if (vAlign != null) {
// 垂直居中
setTcVAlign(tc, vAlign);
}
P p = new P();
if (hAlign != null) {
PPr pPr = new PPr();
Jc jc = new Jc();
// 单元格居中对齐
jc.setVal(hAlign);
pPr.setJc(jc);
p.setPPr(pPr);
}
R run = new R();
p.getContent().add(run);
tc.getContent().add(p);
tr.getContent().add(tc);
}
} else {
// 大部分情况都不会走到这一步
Tr firstTr = getTblAllTr(tbl).get(0);
int cellSize = getTcCellSizeWithMergeNum(firstTr);
for (int i = 0; i < cellSize; i++) {
Tc tc = new Tc();
if (vAlign != null) {
// 垂直居中
setTcVAlign(tc, vAlign);
}
P p = new P();
if (hAlign != null) {
PPr pPr = new PPr();
Jc jc = new Jc();
// 单元格居中对齐
jc.setVal(hAlign);
pPr.setJc(jc);
p.setPPr(pPr);
}
R run = new R();
p.getContent().add(run);
tc.getContent().add(p);
tr.getContent().add(tc);
}
}
if (index >= 0 && index < tbl.getContent().size()) {
tbl.getContent().add(index, tr);
} else {
tbl.getContent().add(tr);
}
}
Aggregations