Search in sources :

Example 16 with TblPr

use of org.docx4j.wml.TblPr in project docx4j-template by vindell.

the class Docx4J_例子2 method addBorders.

// 表格增加边框 可以设置上下左右四个边框样式以及横竖水平线样式
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);
}
Also used : TblBorders(org.docx4j.wml.TblBorders) TblPr(org.docx4j.wml.TblPr)

Example 17 with TblPr

use of org.docx4j.wml.TblPr in project docx4j-template by vindell.

the class Docx4J_例子2 method addBorders.

// 表格增加边框
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);
}
Also used : CTBorder(org.docx4j.wml.CTBorder) BigInteger(java.math.BigInteger) TblBorders(org.docx4j.wml.TblBorders) TblPr(org.docx4j.wml.TblPr)

Example 18 with TblPr

use of org.docx4j.wml.TblPr in project docx4j-template by vindell.

the class Docx4J_例子2 method setTableGridCol.

// 设置整列宽度
/**
 * @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();
    // 这一行是必须的,不自己设置宽度默认是auto
    tblWidth.setType("dxa");
    tblWidth.setW(new BigInteger(tableWidth + ""));
    tblPr.setTblW(tblWidth);
    table.setTblPr(tblPr);
}
Also used : TblWidth(org.docx4j.wml.TblWidth) BigInteger(java.math.BigInteger) TblPr(org.docx4j.wml.TblPr) STHint(org.docx4j.wml.STHint) TblGrid(org.docx4j.wml.TblGrid) TblGridCol(org.docx4j.wml.TblGridCol)

Example 19 with TblPr

use of org.docx4j.wml.TblPr in project docx4j-template by vindell.

the class Docx4J_简单例子2 method setTableGridCol.

// 设置整列宽度
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();
    // 这一行是必须的,不自己设置宽度默认是auto
    tblWidth.setType("dxa");
    tblWidth.setW(new BigInteger("" + width));
    tblPr.setTblW(tblWidth);
    table.setTblPr(tblPr);
}
Also used : TblWidth(org.docx4j.wml.TblWidth) BigInteger(java.math.BigInteger) TblPr(org.docx4j.wml.TblPr) STHint(org.docx4j.wml.STHint) TblGrid(org.docx4j.wml.TblGrid) TblGridCol(org.docx4j.wml.TblGridCol)

Example 20 with TblPr

use of org.docx4j.wml.TblPr 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);
}
Also used : P(org.docx4j.wml.P) RPr(org.docx4j.wml.RPr) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) TblPr(org.docx4j.wml.TblPr) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) Tc(org.docx4j.wml.Tc)

Aggregations

TblPr (org.docx4j.wml.TblPr)26 BigInteger (java.math.BigInteger)14 TblBorders (org.docx4j.wml.TblBorders)10 CTBorder (org.docx4j.wml.CTBorder)9 TblWidth (org.docx4j.wml.TblWidth)8 Tbl (org.docx4j.wml.Tbl)7 Tr (org.docx4j.wml.Tr)7 Jc (org.docx4j.wml.Jc)5 Tc (org.docx4j.wml.Tc)5 TblStyle (org.docx4j.wml.CTTblPrBase.TblStyle)4 CTVerticalJc (org.docx4j.wml.CTVerticalJc)4 P (org.docx4j.wml.P)4 STVerticalJc (org.docx4j.wml.STVerticalJc)4 TblGrid (org.docx4j.wml.TblGrid)3 TblGridCol (org.docx4j.wml.TblGridCol)3 TcPr (org.docx4j.wml.TcPr)3 File (java.io.File)2 STHint (org.docx4j.wml.STHint)2 TrPr (org.docx4j.wml.TrPr)2 FileNotFoundException (java.io.FileNotFoundException)1