use of org.docx4j.wml.TblWidth in project Java-Tutorial by gpcodervn.
the class NestedTable method main.
public static void main(String[] args) throws Exception {
System.out.println("Creating package..");
wordMLPackage = WordprocessingMLPackage.createPackage();
Tbl tblCredProg = factory.createTbl();
TblPr tblPr = new TblPr();
TblStyle tblStyle = new TblStyle();
tblStyle.setVal("TableGrid");
tblPr.setTblStyle(tblStyle);
tblCredProg.setTblPr(tblPr);
TblWidth width = new TblWidth();
width.setType("auto");
width.setW(new BigInteger("0"));
tblPr.setTblW(width);
// create row 1
Tr tr = factory.createTr();
// col 1 of row 1
addTc(tr, "A");
// col 2 of row 1
addTc(tr, "B");
tblCredProg.getEGContentRowContent().add(tr);
// create row 2
Tr tr2 = factory.createTr();
TrPr pr = new TrPr();
tr2.setTrPr(pr);
// col 1 of row 2
Tc tc1 = factory.createTc();
TcPr tcPr = new TcPr();
TblWidth widtha = new TblWidth();
widtha.setType("auto");
widtha.setW(new BigInteger("0"));
tcPr.setTcW(widtha);
tc1.setTcPr(tcPr);
tc1.getEGBlockLevelElts().add(XmlUtils.unmarshalString(tblXML));
// The following is important or you may get a corrupted docx file
tc1.getEGBlockLevelElts().add(wordMLPackage.getMainDocumentPart().createParagraphOfText(""));
tr2.getEGContentCellContent().add(tc1);
tblCredProg.getEGContentRowContent().add(tr2);
// col2 of row 2
addTc(tr2, "C");
wordMLPackage.getMainDocumentPart().addObject(tblCredProg);
// Now save it
wordMLPackage.save(new java.io.File("output/NestedTable.docx"));
System.out.println("Done.");
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4jStyle_S3 method setCellWidth.
public void setCellWidth(Tc tableCell, int width) {
if (width > 0) {
TcPr tableCellProperties = tableCell.getTcPr();
if (tableCellProperties == null) {
tableCellProperties = new TcPr();
tableCell.setTcPr(tableCellProperties);
}
TblWidth tableWidth = new TblWidth();
tableWidth.setType("dxa");
tableWidth.setW(BigInteger.valueOf(width));
tableCellProperties.setTcW(tableWidth);
}
}
use of org.docx4j.wml.TblWidth in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setTableWidth.
/**
* @Description: 设置表格总宽度
*/
public void setTableWidth(Tbl tbl, String width) {
if (StringUtils.isNotBlank(width)) {
TblPr tblPr = getTblPr(tbl);
TblWidth tblW = tblPr.getTblW();
if (tblW == null) {
tblW = new TblWidth();
tblPr.setTblW(tblW);
}
tblW.setW(new BigInteger(width));
tblW.setType("dxa");
}
}
use of org.docx4j.wml.TblWidth in project TranskribusCore by Transkribus.
the class DocxBuilder method applyGridSpan.
private static void applyGridSpan(final Tc cell, final int colSpan, final String rowSpan, int w, boolean mergedVertical) {
TcPr tcPr = factory.createTcPr();
TblWidth tblWidth = factory.createTblWidth();
tblWidth.setType("dxa");
tblWidth.setW(BigInteger.valueOf(w * colSpan));
tcPr.setTcW(tblWidth);
if (colSpan > 1) {
GridSpan gridSpan = factory.createTcPrInnerGridSpan();
gridSpan.setVal(BigInteger.valueOf(colSpan));
tcPr.setGridSpan(gridSpan);
}
if (mergedVertical) {
// logger.debug(" this is vertical span");
VMerge gridVSpan = factory.createTcPrInnerVMerge();
if (rowSpan != null)
gridVSpan.setVal(rowSpan);
tcPr.setVMerge(gridVSpan);
}
cell.setTcPr(tcPr);
}
use of org.docx4j.wml.TblWidth in project mdw-designer by CenturyLinkCloud.
the class DocxBuilder method addTable.
public Tbl addTable(String[] headers, String[][] values, int fontSize, int indent) {
ObjectFactory factory = Context.getWmlObjectFactory();
int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
int cols = headers.length;
int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
Tbl tbl = TblFactory.createTable(0, cols, cellWidthTwips);
Tr thead = factory.createTr();
for (int i = 0; i < headers.length; i++) {
Tc tc = factory.createTc();
tc.getContent().add(createParagraph(headers[i], fontSize, true));
thead.getContent().add(tc);
}
tbl.getContent().add(0, thead);
for (int i = 0; i < values[0].length; i++) {
Tr tr = factory.createTr();
for (int j = 0; j < headers.length; j++) {
Tc tc = factory.createTc();
tc.getContent().add(createParagraph(values[j][i], fontSize, false));
tr.getContent().add(tc);
}
tbl.getContent().add(i + 1, tr);
}
getMdp().addObject(tbl);
if (indent != 0) {
TblPr tblPr = tbl.getTblPr();
TblWidth tblIndent = factory.createTblWidth();
tblIndent.setType("dxa");
tblIndent.setW(BigInteger.valueOf(indent));
tblPr.setTblInd(tblIndent);
}
return tbl;
}
Aggregations