Java Code Examples for org.docx4j.wml.Tbl#setTblPr()
The following examples show how to use
org.docx4j.wml.Tbl#setTblPr() .
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: WordprocessingMLPackageRender.java From docx4j-template with Apache License 2.0 | 7 votes |
public 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); }
Example 2
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
public void addBorders(Tbl table, String borderSize) { table.setTblPr(new TblPr()); CTBorder border = new CTBorder(); border.setColor("auto"); border.setSz(new BigInteger(borderSize)); 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); }
Example 3
Source File: TableWithBorders.java From docx4j-template with Apache License 2.0 | 6 votes |
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); }
Example 4
Source File: TableWithStyledContent.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * 本方法给表格添加边框 */ 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); }
Example 5
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * @param tableWidthPercent * 表格占页面宽度百分比 * @param widthPercent * 各列百分比 */ public void setTableGridCol(WordprocessingMLPackage wordPackage, ObjectFactory factory, Tbl table, double tableWidthPercent, double[] widthPercent) throws Exception { int width = getWritableWidth(wordPackage); int tableWidth = (int) (width * tableWidthPercent / 100); TblGrid tblGrid = factory.createTblGrid(); for (int i = 0; i < widthPercent.length; i++) { TblGridCol gridCol = factory.createTblGridCol(); gridCol.setW(BigInteger.valueOf((long) (tableWidth * widthPercent[i] / 100))); tblGrid.getGridCol().add(gridCol); } table.setTblGrid(tblGrid); TblPr tblPr = table.getTblPr(); if (tblPr == null) { tblPr = factory.createTblPr(); } TblWidth tblWidth = new TblWidth(); tblWidth.setType("dxa");// 这一行是必须的,不自己设置宽度默认是auto tblWidth.setW(new BigInteger(tableWidth + "")); tblPr.setTblW(tblWidth); table.setTblPr(tblPr); }
Example 6
Source File: SettingColumnWidthForTable.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * 本方法为表格添加边框 */ 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); }
Example 7
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public void addBorders(Tbl table, String borderSize) { table.setTblPr(new TblPr()); CTBorder border = new CTBorder(); border.setColor("auto"); border.setSz(new BigInteger(borderSize)); 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); }
Example 8
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public void addBorders(Tbl table, String borderSize) { table.setTblPr(new TblPr()); CTBorder border = new CTBorder(); border.setColor("auto"); border.setSz(new BigInteger(borderSize)); 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); }
Example 9
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public void setTableGridCol(WordprocessingMLPackage wordPackage,ObjectFactory factory,Tbl table,double[] widthPercent) throws Exception{ int width=getWritableWidth(wordPackage); TblGrid tblGrid = factory.createTblGrid(); for (int i = 0; i <widthPercent.length; i++) { TblGridCol gridCol = factory.createTblGridCol(); gridCol.setW(BigInteger.valueOf((long) (width*widthPercent[i]/100))); tblGrid.getGridCol().add(gridCol); } table.setTblGrid(tblGrid); TblPr tblPr=table.getTblPr(); if(tblPr==null){ tblPr=factory.createTblPr(); } TblWidth tblWidth=new TblWidth(); tblWidth.setType("dxa");//这一行是必须的,不自己设置宽度默认是auto tblWidth.setW(new BigInteger(""+width)); tblPr.setTblW(tblWidth); table.setTblPr(tblPr); }
Example 10
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public void addBorders(Tbl table, CTBorder topBorder, CTBorder bottomBorder, CTBorder leftBorder, CTBorder rightBorder, CTBorder hBorder, CTBorder vBorder) { table.setTblPr(new TblPr()); TblBorders borders = new TblBorders(); borders.setBottom(bottomBorder); borders.setLeft(leftBorder); borders.setRight(rightBorder); borders.setTop(bottomBorder); borders.setInsideH(hBorder); borders.setInsideV(vBorder); table.getTblPr().setTblBorders(borders); }
Example 11
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
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); }
Example 12
Source File: AddingAnInlineImageToTable.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * 给表格添加简单的黑色边框. * @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); }
Example 13
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
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); }
Example 14
Source File: WmlElementUtils.java From docx4j-template with Apache License 2.0 | 5 votes |
public static TblPr getTblPr(Tbl tbl) { TblPr tblPr = tbl.getTblPr(); if (tblPr == null) { tblPr = new TblPr(); tbl.setTblPr(tblPr); } return tblPr; }
Example 15
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
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); }
Example 16
Source File: RoundtripXHTMLImporter.java From docx-html-editor with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void setupTblPr(TableBox cssTable, Tbl tbl, TableProperties tableProperties) { /* * Reinstate * context.getWmlPackage().setUserData(id+"#Pr", table.getTblPr()); as set by SessionAwareAbstractTableWriter */ String id = cssTable.getElement().getAttribute("id"); if (id==null ) { log.debug("no id on table " ); } else { log.debug("processing table with id " + id); Object o = wordMLPackage.getUserData(id+"#Pr"); if (o==null) { log.debug("no #Pr UserData on table with id " + id); } else { tbl.setTblPr((TblPr)o); return; } } // we need to fall back for a newly created table super.setupTblPr( cssTable, tbl, tableProperties); }
Example 17
Source File: Docx4j_工具类_S3_Test.java From docx4j-template with Apache License 2.0 | 5 votes |
public TblPr getTblPr(Tbl tbl) { TblPr tblPr = tbl.getTblPr(); if (tblPr == null) { tblPr = new TblPr(); tbl.setTblPr(tblPr); } return tblPr; }
Example 18
Source File: Docx4j_Helper.java From docx4j-template with Apache License 2.0 | 4 votes |
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); }
Example 19
Source File: Docx4j_工具类_S3_Test.java From docx4j-template with Apache License 2.0 | 4 votes |
/** * @Description:创建表格(默认水平居中,垂直居中) */ public Tbl createTable(int rowNum, int colsNum, int[] widthArr) throws Exception { colsNum = Math.max(1, Math.min(colsNum, widthArr.length)); rowNum = Math.max(1, rowNum); Tbl tbl = new Tbl(); StringBuffer tblSb = new StringBuffer(); tblSb.append("<w:tblPr ").append(Namespaces.W_NAMESPACE_DECLARATION) .append(">"); tblSb.append("<w:tblStyle w:val=\"TableGrid\"/>"); tblSb.append("<w:tblW w:w=\"0\" w:type=\"auto\"/>"); // 上边框 tblSb.append("<w:tblBorders>"); tblSb.append("<w:top w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); // 左边框 tblSb.append("<w:left w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); // 下边框 tblSb.append("<w:bottom w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); // 右边框 tblSb.append("<w:right w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); tblSb.append("<w:insideH w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); tblSb.append("<w:insideV w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); tblSb.append("</w:tblBorders>"); tblSb.append("</w:tblPr>"); TblPr tblPr = null; tblPr = (TblPr) XmlUtils.unmarshalString(tblSb.toString()); Jc jc = new Jc(); // 单元格居中对齐 jc.setVal(JcEnumeration.CENTER); tblPr.setJc(jc); tbl.setTblPr(tblPr); // 设定各单元格宽度 TblGrid tblGrid = new TblGrid(); tbl.setTblGrid(tblGrid); for (int i = 0; i < colsNum; i++) { TblGridCol gridCol = new TblGridCol(); gridCol.setW(BigInteger.valueOf(widthArr[i])); tblGrid.getGridCol().add(gridCol); } // 新增行 for (int j = 0; j < rowNum; j++) { Tr tr = new Tr(); tbl.getContent().add(tr); // 列 for (int i = 0; i < colsNum; i++) { Tc tc = new Tc(); tr.getContent().add(tc); TcPr tcPr = new TcPr(); TblWidth cellWidth = new TblWidth(); cellWidth.setType("dxa"); cellWidth.setW(BigInteger.valueOf(widthArr[i])); tcPr.setTcW(cellWidth); tc.setTcPr(tcPr); // 垂直居中 setTcVAlign(tc, STVerticalJc.CENTER); P p = new P(); PPr pPr = new PPr(); pPr.setJc(jc); p.setPPr(pPr); R run = new R(); p.getContent().add(run); tc.getContent().add(p); } } return tbl; }
Example 20
Source File: WmlElementUtils.java From docx4j-template with Apache License 2.0 | 4 votes |
/** * @Description:创建表格(默认水平居中,垂直居中) */ public static Tbl createTable(int rowNum, int colsNum, int[] widthArr) throws Exception { colsNum = Math.max(1, Math.min(colsNum, widthArr.length)); rowNum = Math.max(1, rowNum); Tbl tbl = new Tbl(); StringBuffer tblSb = new StringBuffer(); tblSb.append("<w:tblPr ").append(Namespaces.W_NAMESPACE_DECLARATION).append(">"); tblSb.append("<w:tblStyle w:val=\"TableGrid\"/>"); tblSb.append("<w:tblW w:w=\"0\" w:type=\"auto\"/>"); // 上边框 tblSb.append("<w:tblBorders>"); tblSb.append("<w:top w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); // 左边框 tblSb.append("<w:left w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); // 下边框 tblSb.append("<w:bottom w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); // 右边框 tblSb.append("<w:right w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); tblSb.append("<w:insideH w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); tblSb.append("<w:insideV w:val=\"single\" w:sz=\"1\" w:space=\"0\" w:color=\"auto\"/>"); tblSb.append("</w:tblBorders>"); tblSb.append("</w:tblPr>"); TblPr tblPr = null; tblPr = (TblPr) XmlUtils.unmarshalString(tblSb.toString()); Jc jc = new Jc(); // 单元格居中对齐 jc.setVal(JcEnumeration.CENTER); tblPr.setJc(jc); tbl.setTblPr(tblPr); // 设定各单元格宽度 TblGrid tblGrid = new TblGrid(); tbl.setTblGrid(tblGrid); for (int i = 0; i < colsNum; i++) { TblGridCol gridCol = new TblGridCol(); gridCol.setW(BigInteger.valueOf(widthArr[i])); tblGrid.getGridCol().add(gridCol); } // 新增行 for (int j = 0; j < rowNum; j++) { Tr tr = new Tr(); tbl.getContent().add(tr); // 列 for (int i = 0; i < colsNum; i++) { Tc tc = new Tc(); tr.getContent().add(tc); TcPr tcPr = new TcPr(); TblWidth cellWidth = new TblWidth(); cellWidth.setType("dxa"); cellWidth.setW(BigInteger.valueOf(widthArr[i])); tcPr.setTcW(cellWidth); tc.setTcPr(tcPr); // 垂直居中 setTcVAlign(tc, STVerticalJc.CENTER); P p = new P(); PPr pPr = new PPr(); pPr.setJc(jc); p.setPPr(pPr); R run = new R(); p.getContent().add(run); tc.getContent().add(p); } } return tbl; }