use of org.docx4j.wml.TblWidth in project Java-Tutorial by gpcodervn.
the class ComplexTable method addTc.
private static void addTc(Tr tr, String label, String text, String width) {
Tc tc = factory.createTc();
TcPr tcPr = new TcPr();
TblWidth tblwidth = new TblWidth();
tblwidth.setType("dxa");
tblwidth.setW(new BigInteger(width));
tcPr.setTcW(tblwidth);
tc.setTcPr(tcPr);
tc.getEGBlockLevelElts().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(text));
tr.getEGContentCellContent().add(tc);
}
use of org.docx4j.wml.TblWidth in project Java-Tutorial by gpcodervn.
the class NestedTable method addTc.
protected static void addTc(Tr tr, String text) {
Tc tc = factory.createTc();
TcPr tcPr = new TcPr();
TblWidth width = new TblWidth();
width.setType("dxa");
width.setW(new BigInteger("3192"));
tcPr.setTcW(width);
tc.setTcPr(tcPr);
tc.getEGBlockLevelElts().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(text));
tr.getEGContentCellContent().add(tc);
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4J_例子2 method setTableGridCol.
// 设置整列宽度
/**
* @param tableWidthPercent
* 表格占页面宽度百分比
* @param widthPercent
* 各列百分比
*/
public void setTableGridCol(WordprocessingMLPackage wordPackage, ObjectFactory factory, Tbl table, double tableWidthPercent, double[] widthPercent) throws Exception {
int width = getWritableWidth(wordPackage);
int tableWidth = (int) (width * tableWidthPercent / 100);
TblGrid tblGrid = factory.createTblGrid();
for (int i = 0; i < widthPercent.length; i++) {
TblGridCol gridCol = factory.createTblGridCol();
gridCol.setW(BigInteger.valueOf((long) (tableWidth * widthPercent[i] / 100)));
tblGrid.getGridCol().add(gridCol);
}
table.setTblGrid(tblGrid);
TblPr tblPr = table.getTblPr();
if (tblPr == null) {
tblPr = factory.createTblPr();
}
TblWidth tblWidth = new TblWidth();
// 这一行是必须的,不自己设置宽度默认是auto
tblWidth.setType("dxa");
tblWidth.setW(new BigInteger(tableWidth + ""));
tblPr.setTblW(tblWidth);
table.setTblPr(tblPr);
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4J_简单例子2 method setTableGridCol.
// 设置整列宽度
public void setTableGridCol(WordprocessingMLPackage wordPackage, ObjectFactory factory, Tbl table, double[] widthPercent) throws Exception {
int width = getWritableWidth(wordPackage);
TblGrid tblGrid = factory.createTblGrid();
for (int i = 0; i < widthPercent.length; i++) {
TblGridCol gridCol = factory.createTblGridCol();
gridCol.setW(BigInteger.valueOf((long) (width * widthPercent[i] / 100)));
tblGrid.getGridCol().add(gridCol);
}
table.setTblGrid(tblGrid);
TblPr tblPr = table.getTblPr();
if (tblPr == null) {
tblPr = factory.createTblPr();
}
TblWidth tblWidth = new TblWidth();
// 这一行是必须的,不自己设置宽度默认是auto
tblWidth.setType("dxa");
tblWidth.setW(new BigInteger("" + width));
tblPr.setTblW(tblWidth);
table.setTblPr(tblPr);
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4jStyle_S3 method setCellMargins.
public void setCellMargins(Tc tableCell, int top, int right, int bottom, int left) {
TcPr tableCellProperties = tableCell.getTcPr();
if (tableCellProperties == null) {
tableCellProperties = new TcPr();
tableCell.setTcPr(tableCellProperties);
}
TcMar margins = new TcMar();
if (bottom > 0) {
TblWidth bW = new TblWidth();
bW.setType("dxa");
bW.setW(BigInteger.valueOf(bottom));
margins.setBottom(bW);
}
if (top > 0) {
TblWidth tW = new TblWidth();
tW.setType("dxa");
tW.setW(BigInteger.valueOf(top));
margins.setTop(tW);
}
if (left > 0) {
TblWidth lW = new TblWidth();
lW.setType("dxa");
lW.setW(BigInteger.valueOf(left));
margins.setLeft(lW);
}
if (right > 0) {
TblWidth rW = new TblWidth();
rW.setType("dxa");
rW.setW(BigInteger.valueOf(right));
margins.setRight(rW);
}
tableCellProperties.setTcMar(margins);
}
Aggregations