use of org.docx4j.wml.Tc 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;
}
use of org.docx4j.wml.Tc in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method getTblContentList.
/**
* @Description: 获取表格内容
*/
public List<String> getTblContentList(Tbl tbl) throws Exception {
List<String> resultList = new ArrayList<String>();
List<Tr> trList = getTblAllTr(tbl);
for (Tr tr : trList) {
StringBuffer sb = new StringBuffer();
List<Tc> tcList = getTrAllCell(tr);
for (Tc tc : tcList) {
sb.append(getElementContent(tc) + ",");
}
resultList.add(sb.toString());
}
return resultList;
}
use of org.docx4j.wml.Tc in project docx4j-template by vindell.
the class Docx4j_替换模板 method mergeCellsVertically.
/**
* @Description: 跨行合并
*/
public static 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 = factory.createTcPrInnerVMerge();
tcPr.setVMerge(vMerge);
}
if (rowIndex == fromRow) {
vMerge.setVal("restart");
} else {
vMerge.setVal("continue");
}
}
}
use of org.docx4j.wml.Tc in project docx4j-template by vindell.
the class Docx4j_替换模板 method replaceTrTotalData.
/**
* 替换表格合计数据
*/
private void replaceTrTotalData(Tr tr, String[] dataArr) {
List<Object> tcObjList = tr.getContent();
Tc tc = null;
// 跳过合计
for (int i = 2, len = tcObjList.size(); i < len; i++) {
tc = (Tc) XmlUtils.unwrap(tcObjList.get(i));
replaceTcContent(tc, dataArr[i - 2]);
}
}
use of org.docx4j.wml.Tc in project docx4j-template by vindell.
the class Docx4j_替换模板 method getTrAllCell.
public static List<Tc> getTrAllCell(Tr tr) {
List<Object> objList = getAllElementFromObject(tr, Tc.class);
List<Tc> tcList = new ArrayList<Tc>();
if (objList == null) {
return tcList;
}
for (Object tcObj : objList) {
if (tcObj instanceof Tc) {
Tc objTc = (Tc) tcObj;
tcList.add(objTc);
}
}
return tcList;
}
Aggregations