use of org.docx4j.wml.TblPr in project docx4j-template by vindell.
the class TableWithStyledContent method addBorders.
/**
* 本方法给表格添加边框
*/
private static void addBorders(Tbl table) {
table.setTblPr(new TblPr());
CTBorder border = new CTBorder();
border.setColor("auto");
border.setSz(new BigInteger("4"));
border.setSpace(new BigInteger("0"));
border.setVal(STBorder.SINGLE);
TblBorders borders = new TblBorders();
borders.setBottom(border);
borders.setLeft(border);
borders.setRight(border);
borders.setTop(border);
borders.setInsideH(border);
borders.setInsideV(border);
table.getTblPr().setTblBorders(borders);
}
use of org.docx4j.wml.TblPr in project docx4j-template by vindell.
the class AddingAnInlineImageToTable method addBorders.
/**
* 给表格添加简单的黑色边框.
* @param table
*/
private static void addBorders(Tbl table) {
table.setTblPr(new TblPr());
CTBorder border = BorderUtils.ctBorder();
TblBorders borders = BorderUtils.tblBorders(border);
table.getTblPr().setTblBorders(borders);
}
use of org.docx4j.wml.TblPr 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;
}
use of org.docx4j.wml.TblPr in project Java-Tutorial by gpcodervn.
the class Docx4jUtils method createTableWithContent.
/**
* Our createTableWithContent method follows (we use dxa values). There are 4
* rows, some cells with vertical merge, and some with horizontal merge.
*/
private Tbl createTableWithContent() {
Tbl table = factory.createTbl();
// for TEST: this adds borders to all cells
TblPr tblPr = new TblPr();
TblStyle tblStyle = new TblStyle();
tblStyle.setVal("TableGrid");
tblPr.setTblStyle(tblStyle);
table.setTblPr(tblPr);
Tr tableRow = factory.createTr();
// a default table cell style
DocxStyle defStyle = new DocxStyle();
defStyle.setBold(false);
defStyle.setItalic(false);
defStyle.setUnderline(false);
defStyle.setHorizAlignment(JcEnumeration.CENTER);
// a specific table cell style
DocxStyle style = new DocxStyle();
style.setBold(true);
style.setItalic(true);
style.setUnderline(true);
style.setFontSize("40");
style.setFontColor("FF0000");
style.setFontFamily("Book Antiqua");
style.setTop(300);
style.setBackground("CCFFCC");
style.setVerticalAlignment(STVerticalJc.CENTER);
style.setHorizAlignment(JcEnumeration.CENTER);
style.setBorderTop(true);
style.setBorderBottom(true);
style.setNoWrap(true);
addTableCell(tableRow, "Field 1", 3500, style, 1, null);
// start vertical merge for Filed 2 and Field 3 on 3 rows
addTableCell(tableRow, "Field 2", 3500, defStyle, 1, "restart");
addTableCell(tableRow, "Field 3", 1500, defStyle, 1, "restart");
table.getContent().add(tableRow);
tableRow = factory.createTr();
addTableCell(tableRow, "Text", 3500, defStyle, 1, null);
addTableCell(tableRow, "", 3500, defStyle, 1, "");
addTableCell(tableRow, "", 1500, defStyle, 1, "");
table.getContent().add(tableRow);
tableRow = factory.createTr();
addTableCell(tableRow, "Interval", 3500, defStyle, 1, null);
addTableCell(tableRow, "", 3500, defStyle, 1, "close");
addTableCell(tableRow, "", 1500, defStyle, 1, "close");
table.getContent().add(tableRow);
// add an image horizontally merged on 3 cells
String filenameHint = null;
String altText = null;
int id1 = 0;
int id2 = 1;
byte[] bytes;
try {
bytes = getImageBytes(new File("/resources/image.png"));
P pImage = newImage(wordMLPackage, bytes, filenameHint, altText, id1, id2, 8500);
tableRow = factory.createTr();
addTableCell(tableRow, pImage, 8500, defStyle, 3, null);
table.getContent().add(tableRow);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return table;
}
use of org.docx4j.wml.TblPr in project docx4j-template by vindell.
the class Docx4J_例子2 method setTableAlign.
// 表格水平对齐方式
public void setTableAlign(ObjectFactory factory, Tbl table, JcEnumeration jcEnumeration) {
TblPr tablePr = table.getTblPr();
if (tablePr == null) {
tablePr = factory.createTblPr();
}
Jc jc = tablePr.getJc();
if (jc == null) {
jc = new Jc();
}
jc.setVal(jcEnumeration);
tablePr.setJc(jc);
table.setTblPr(tablePr);
}
Aggregations