use of org.docx4j.wml.TrPr in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setTrHeight.
/**
* @Description:设置tr高度
*/
public void setTrHeight(Tr tr, String heigth) {
TrPr trPr = getTrPr(tr);
CTHeight ctHeight = new CTHeight();
ctHeight.setVal(new BigInteger(heigth));
TrHeight trHeight = new TrHeight(ctHeight);
trHeight.set(trPr);
}
use of org.docx4j.wml.TrPr in project docx4j-template by vindell.
the class Docx4j_替换模板 method replaceTrData.
/**
* 替换tr数据,其他插入
*/
private void replaceTrData(Tbl tbl, Tr tr, List<String[]> dataList, int trIndex) throws Exception {
TrPr trPr = XmlUtils.deepCopy(tr.getTrPr());
String tcContent = null;
String[] tcMarshaArr = getTcMarshalStr(tr);
String[] dataArr = null;
for (int i = 0, iLen = dataList.size(); i < iLen; i++) {
dataArr = dataList.get(i);
Tr newTr = null;
Tc newTc = null;
if (i == 0) {
newTr = tr;
} else {
newTr = factory.createTr();
if (trPr != null) {
newTr.setTrPr(trPr);
}
newTc = factory.createTc();
newTr.getContent().add(newTc);
}
for (int j = 0, jLen = dataArr.length; j < jLen; j++) {
tcContent = tcMarshaArr[j];
if (tcContent != null) {
tcContent = tcContent.replaceAll("(<w:t>)(.*?)(</w:t>)", "<w:t>" + dataArr[j] + "</w:t>");
newTc = (Tc) XmlUtils.unmarshalString(tcContent);
} else {
newTc = factory.createTc();
setNewTcContent(newTc, dataArr[j]);
}
// 新增tr
if (i != 0) {
newTr.getContent().add(newTc);
} else {
// 替换
newTr.getContent().set(j + 1, newTc);
}
}
if (i != 0) {
tbl.getContent().add(trIndex + i, newTr);
}
}
}
Aggregations