Hello Jason,
Here is the code snippet which I have written for WordML and also to set the table width:
- Code: Select all
File reportFile = new File(System.getProperty("user.dir"), "Draft Report.docx");
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.createPackage();
Tbl jpegTable = TblFactory.createTable(0, 0, 8000);
jpegTable = setTableWidth(jpegTable, 8700);
Tr tableRow1 = objectFactory.createTr();
Tr tableRow2 = objectFactory.createTr();
jpegTable.getEGContentRowContent().add(tableRow1);
jpegTable.getEGContentRowContent().add(tableRow2);
wordMLPackage.getMainDocumentPart().addObject(jpegTable);
private static Tbl setTableWidth(Tbl tbl, long width){
TblPr tblPr = objectFactory.createTblPr();
TblWidth tblWidth = objectFactory.createTblWidth();
tblWidth.setW(BigInteger.valueOf(width));
tblWidth.setType("dxa"); // twips
tblPr.setTblW(tblWidth);
tbl.setTblPr(tblPr);
return tbl;
}
Hope this helps, let me know if you need more info.
Rgds,
Sharad