use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setTableCellMargin.
/**
* @Description: 设置单元格Margin
*/
public void setTableCellMargin(Tbl tbl, String top, String right, String bottom, String left) {
TblPr tblPr = getTblPr(tbl);
CTTblCellMar cellMar = tblPr.getTblCellMar();
if (cellMar == null) {
cellMar = new CTTblCellMar();
tblPr.setTblCellMar(cellMar);
}
if (StringUtils.isNotBlank(top)) {
TblWidth topW = new TblWidth();
topW.setW(new BigInteger(top));
topW.setType("dxa");
cellMar.setTop(topW);
}
if (StringUtils.isNotBlank(right)) {
TblWidth rightW = new TblWidth();
rightW.setW(new BigInteger(right));
rightW.setType("dxa");
cellMar.setRight(rightW);
}
if (StringUtils.isNotBlank(bottom)) {
TblWidth btW = new TblWidth();
btW.setW(new BigInteger(bottom));
btW.setType("dxa");
cellMar.setBottom(btW);
}
if (StringUtils.isNotBlank(left)) {
TblWidth leftW = new TblWidth();
leftW.setW(new BigInteger(left));
leftW.setType("dxa");
cellMar.setLeft(leftW);
}
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method createTable.
/**
* @Description:创建表格(默认水平居中,垂直居中)
*/
public Tbl createTable(int rowNum, int colsNum, int[] widthArr) throws Exception {
colsNum = Math.max(1, Math.min(colsNum, widthArr.length));
rowNum = Math.max(1, rowNum);
Tbl tbl = new Tbl();
StringBuffer tblSb = new StringBuffer();
tblSb.append("<w:tblPr ").append(Namespaces.W_NAMESPACE_DECLARATION).append(">");
tblSb.append("<w:tblStyle w:val=\"TableGrid\"/>");
tblSb.append("<w:tblW w:w=\"0\" w:type=\"auto\"/>");
// 上边框
tblSb.append("<w:tblBorders>");
tblSb.append("<w:top w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>");
// 左边框
tblSb.append("<w:left w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>");
// 下边框
tblSb.append("<w:bottom w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>");
// 右边框
tblSb.append("<w:right w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>");
tblSb.append("<w:insideH w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>");
tblSb.append("<w:insideV w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>");
tblSb.append("</w:tblBorders>");
tblSb.append("</w:tblPr>");
TblPr tblPr = null;
tblPr = (TblPr) XmlUtils.unmarshalString(tblSb.toString());
Jc jc = new Jc();
// 单元格居中对齐
jc.setVal(JcEnumeration.CENTER);
tblPr.setJc(jc);
tbl.setTblPr(tblPr);
// 设定各单元格宽度
TblGrid tblGrid = new TblGrid();
tbl.setTblGrid(tblGrid);
for (int i = 0; i < colsNum; i++) {
TblGridCol gridCol = new TblGridCol();
gridCol.setW(BigInteger.valueOf(widthArr[i]));
tblGrid.getGridCol().add(gridCol);
}
// 新增行
for (int j = 0; j < rowNum; j++) {
Tr tr = new Tr();
tbl.getContent().add(tr);
// 列
for (int i = 0; i < colsNum; i++) {
Tc tc = new Tc();
tr.getContent().add(tc);
TcPr tcPr = new TcPr();
TblWidth cellWidth = new TblWidth();
cellWidth.setType("dxa");
cellWidth.setW(BigInteger.valueOf(widthArr[i]));
tcPr.setTcW(cellWidth);
tc.setTcPr(tcPr);
// 垂直居中
setTcVAlign(tc, STVerticalJc.CENTER);
P p = new P();
PPr pPr = new PPr();
pPr.setJc(jc);
p.setPPr(pPr);
R run = new R();
p.getContent().add(run);
tc.getContent().add(p);
}
}
return tbl;
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class WordprocessingMLPackageRender method setCellWidth.
/**
* 本方法创建一个单元格属性集对象和一个表格宽度对象. 将给定的宽度设置到宽度对象然后将其添加到 属性集对象. 最后将属性集对象设置到单元格中.
*/
public void setCellWidth(Tc tableCell, int width) {
TcPr tableCellProperties = new TcPr();
TblWidth tableWidth = new TblWidth();
tableWidth.setW(BigInteger.valueOf(width));
tableCellProperties.setTcW(tableWidth);
tableCell.setTcPr(tableCellProperties);
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setTcWidth.
/**
* @Description: 设置单元格宽度
*/
public void setTcWidth(Tc tc, String width) {
if (StringUtils.isNotBlank(width)) {
TcPr tcPr = getTcPr(tc);
TblWidth tcW = tcPr.getTcW();
if (tcW == null) {
tcW = new TblWidth();
tcPr.setTcW(tcW);
}
tcW.setW(new BigInteger(width));
tcW.setType("dxa");
}
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class SettingColumnWidthForTable method setCellWidth.
/**
* 本方法创建一个单元格属性集对象和一个表格宽度对象. 将给定的宽度设置到宽度对象然后将其添加到
* 属性集对象. 最后将属性集对象设置到单元格中.
*/
private static void setCellWidth(Tc tableCell, int width) {
TcPr tableCellProperties = new TcPr();
TblWidth tableWidth = new TblWidth();
tableWidth.setW(BigInteger.valueOf(width));
tableCellProperties.setTcW(tableWidth);
tableCell.setTcPr(tableCellProperties);
}
Aggregations