use of org.docx4j.wml.Tbl in project docx4j-template by vindell.
the class Docx4J_例子2 method createNormalTableTest.
public void createNormalTableTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
RPr titleRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false);
RPr contentRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
Tbl table = factory.createTbl();
CTBorder topBorder = new CTBorder();
topBorder.setColor("80C687");
topBorder.setVal(STBorder.DOUBLE);
topBorder.setSz(new BigInteger("2"));
CTBorder leftBorder = new CTBorder();
leftBorder.setVal(STBorder.NONE);
leftBorder.setSz(new BigInteger("0"));
CTBorder hBorder = new CTBorder();
hBorder.setVal(STBorder.SINGLE);
hBorder.setSz(new BigInteger("1"));
addBorders(table, topBorder, topBorder, leftBorder, leftBorder, hBorder, null);
// 百分比
double[] colWidthPercent = new double[] { 15, 20, 20, 20, 25 };
setTableGridCol(wordMLPackage, factory, table, 80, colWidthPercent);
Tr titleRow = factory.createTr();
setTableTrHeight(factory, titleRow, "500");
addTableCell(factory, wordMLPackage, titleRow, "序号", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "姓甚", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "名谁", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "籍贯", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "营生", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
table.getContent().add(titleRow);
for (int i = 0; i < 10; i++) {
Tr contentRow = factory.createTr();
addTableCell(factory, wordMLPackage, contentRow, i + "", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "无名氏", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "佚名", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "武林", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "吟诗赋曲", contentRpr, JcEnumeration.CENTER, false, null);
table.getContent().add(contentRow);
}
setTableAlign(factory, table, JcEnumeration.CENTER);
t.addObject(table);
}
use of org.docx4j.wml.Tbl in project docx4j-template by vindell.
the class Docx4J_简单例子 method createNormalTableTest.
public void createNormalTableTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
RPr titleRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false);
RPr contentRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
Tbl table = factory.createTbl();
addBorders(table, "2");
Tr titleRow = factory.createTr();
addTableCell(factory, wordMLPackage, titleRow, "序号", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "姓甚", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "名谁", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "籍贯", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "营生", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
table.getContent().add(titleRow);
for (int i = 0; i < 10; i++) {
Tr contentRow = factory.createTr();
addTableCell(factory, wordMLPackage, contentRow, i + "", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "无名氏", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "佚名", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "武林", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "吟诗赋曲", contentRpr, JcEnumeration.CENTER, false, null);
table.getContent().add(contentRow);
}
setTableAlign(factory, table, JcEnumeration.CENTER);
t.addObject(table);
}
use of org.docx4j.wml.Tbl in project docx4j-template by vindell.
the class Docx4J_简单例子2 method createNormalTableTest.
public void createNormalTableTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
RPr titleRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false);
RPr contentRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
Tbl table = factory.createTbl();
addBorders(table, "2");
// 百分比
double[] widthPercent = new double[] { 15, 20, 20, 20, 25 };
setTableGridCol(wordMLPackage, factory, table, widthPercent);
Tr titleRow = factory.createTr();
setTableTrHeight(factory, titleRow, "500");
addTableCell(factory, wordMLPackage, titleRow, "序号", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "姓甚", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "名谁", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "籍贯", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
addTableCell(factory, wordMLPackage, titleRow, "营生", titleRpr, JcEnumeration.CENTER, true, "C6D9F1");
table.getContent().add(titleRow);
for (int i = 0; i < 10; i++) {
Tr contentRow = factory.createTr();
addTableCell(factory, wordMLPackage, contentRow, i + "", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "无名氏", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "佚名", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "武林", contentRpr, JcEnumeration.CENTER, false, null);
addTableCell(factory, wordMLPackage, contentRow, "吟诗赋曲", contentRpr, JcEnumeration.CENTER, false, null);
table.getContent().add(contentRow);
}
setTableAlign(factory, table, JcEnumeration.CENTER);
t.addObject(table);
}
use of org.docx4j.wml.Tbl in project docx4j-template by vindell.
the class Docx4j_Helper method name.
public static void name() throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
String titleStr = "测试插入段落";
P p = Docx4j_Helper.factory.createP();
String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>";
RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr);
setParagraphContent(p, rpr, titleStr);
documentPart.getContent().add(5, p);
String tblPrStr = "<w:tblPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:tblW w:w=\"8522\" w:type=\"dxa\"/><w:tblBorders><w:top w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:left w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:bottom w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:right w:val=\"single\" w:sz=\"4\" w:space=\"0\"/><w:insideH w:val=\"single\" w:sz=\"4\" w:space=\"0\"/></w:tblBorders></w:tblPr>";
Tbl tbl = Docx4j_Helper.factory.createTbl();
TblPr tblPr = (TblPr) XmlUtils.unmarshalString(tblPrStr);
tbl.setTblPr(tblPr);
Tr tr = Docx4j_Helper.factory.createTr();
Tc tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tbl.getContent().add(tr);
tr = Docx4j_Helper.factory.createTr();
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tc = Docx4j_Helper.factory.createTc();
tr.getContent().add(tc);
tbl.getContent().add(tr);
documentPart.getContent().add(9, tbl);
// Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);
}
use of org.docx4j.wml.Tbl in project docx4j-template by vindell.
the class Docx4jStyle_S3 method createTableWithContent.
public Tbl createTableWithContent(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, String imgFilePath) throws Exception {
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
Docx4jStyle_S3 defStyle = new Docx4jStyle_S3();
defStyle.setBold(false);
defStyle.setItalic(false);
defStyle.setUnderline(false);
defStyle.setHorizAlignment(JcEnumeration.CENTER);
// a specific table cell style
Docx4jStyle_S3 style = new Docx4jStyle_S3();
style.setBold(true);
style.setItalic(true);
style.setUnderline(true);
style.setFontSize("40");
style.setFontColor("FF0000");
style.setCnFontFamily("微软雅黑");
style.setEnFontFamily("Times New Roman");
style.setTop(300);
style.setBackground("CCFFCC");
style.setVerticalAlignment(STVerticalJc.CENTER);
style.setHorizAlignment(JcEnumeration.CENTER);
style.setBorderTop(true);
style.setBorderBottom(true);
style.setNoWrap(true);
addTableCell(factory, tableRow, "测试Field 1", 3500, style, 1, null);
// start vertical merge for Filed 2 and Field 3 on 3 rows
addTableCell(factory, tableRow, "测试Field 2", 3500, defStyle, 1, "restart");
addTableCell(factory, tableRow, "测试Field 3", 1500, defStyle, 1, "restart");
table.getContent().add(tableRow);
tableRow = factory.createTr();
addTableCell(factory, tableRow, "Text", 3500, defStyle, 1, null);
addTableCell(factory, tableRow, "", 3500, defStyle, 1, "");
addTableCell(factory, tableRow, "", 1500, defStyle, 1, "");
table.getContent().add(tableRow);
tableRow = factory.createTr();
addTableCell(factory, tableRow, "Interval", 3500, defStyle, 1, null);
addTableCell(factory, tableRow, "", 3500, defStyle, 1, "close");
addTableCell(factory, 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 = getImageBytes(imgFilePath);
P pImage;
try {
pImage = newImage(wordMLPackage, factory, bytes, filenameHint, altText, id1, id2, 8500);
tableRow = factory.createTr();
addTableCell(factory, tableRow, pImage, 8500, defStyle, 3, null);
table.getContent().add(tableRow);
} catch (Exception e) {
e.printStackTrace();
}
return table;
}
Aggregations