Java Code Examples for org.docx4j.wml.ObjectFactory#createTbl()
The following examples show how to use
org.docx4j.wml.ObjectFactory#createTbl() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public void createTableTest(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[] colWidthPercent = new double[] { 15, 20, 20, 20, 25 };// 百分比 setTableGridCol(wordMLPackage, factory, table, 100, colWidthPercent); List<String> columnList = new ArrayList<String>(); columnList.add("序号"); columnList.add("姓名信息|姓甚|名谁"); columnList.add("名刺信息|籍贯|营生"); addTableTitleCell(factory, wordMLPackage, table, columnList, titleRpr, JcEnumeration.CENTER, true, "C6D9F1"); 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); }
Example 2
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
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); }
Example 3
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
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); }
Example 4
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
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); }
Example 5
Source File: Docx4j_创建表格_S5_Test.java From docx4j-template with Apache License 2.0 | 4 votes |
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; }