use of org.docx4j.wml.TcPrInner.HMerge in project docx4j-template by vindell.
the class Docx4J_例子2 method createNormalCell.
public void createNormalCell(ObjectFactory factory, Tr tr, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor, boolean isHMerger, String mergeVal) {
Tc tableCell = factory.createTc();
P p = factory.createP();
setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
Text t = factory.createText();
t.setValue(content);
R run = factory.createR();
// 设置表格内容字体样式
run.setRPr(rpr);
TcPr tcPr = tableCell.getTcPr();
if (tcPr == null) {
tcPr = factory.createTcPr();
}
CTVerticalJc valign = factory.createCTVerticalJc();
valign.setVal(STVerticalJc.CENTER);
tcPr.setVAlign(valign);
if (isHMerger) {
HMerge merge = new HMerge();
if (mergeVal != null) {
merge.setVal(mergeVal);
}
tcPr.setHMerge(merge);
} else {
VMerge merge = new VMerge();
if (mergeVal != null) {
merge.setVal(mergeVal);
}
tcPr.setVMerge(merge);
}
run.getContent().add(t);
p.getContent().add(run);
tableCell.getContent().add(p);
if (hasBgColor) {
CTShd shd = tcPr.getShd();
if (shd == null) {
shd = factory.createCTShd();
}
shd.setColor("auto");
shd.setFill(backgroudColor);
tcPr.setShd(shd);
}
tableCell.setTcPr(tcPr);
tr.getContent().add(tableCell);
}
use of org.docx4j.wml.TcPrInner.HMerge in project docx4j-template by vindell.
the class Docx4j_合并单元格_S4_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.TcPrInner.HMerge 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");
}
}
}
Aggregations