Search in sources :

Example 1 with TblBorders

use of org.docx4j.wml.TblBorders in project Java-Tutorial by gpcodervn.

the class TableBordersTest method testTableBorderAbsenceExplicit.

@Test
public void testTableBorderAbsenceExplicit() throws Docx4JException {
    Tbl tbl = table("<table border='0'><tr><td>1</td></tr></table>");
    TblBorders borders = tbl.getTblPr().getTblBorders();
    assertEquals(STBorder.NONE, borders.getTop().getVal());
    assertEquals(STBorder.NONE, borders.getBottom().getVal());
    assertEquals(STBorder.NONE, borders.getLeft().getVal());
    assertEquals(STBorder.NONE, borders.getRight().getVal());
    assertEquals(STBorder.NONE, borders.getInsideH().getVal());
    assertEquals(STBorder.NONE, borders.getInsideV().getVal());
    TcPrInner.TcBorders borders2 = ((Tc) ((Tr) tbl.getContent().get(0)).getContent().get(0)).getTcPr().getTcBorders();
    assertNull(borders2.getTop());
    assertNull(borders2.getBottom());
    assertNull(borders2.getLeft());
    assertNull(borders2.getRight());
    assertNull(borders2.getInsideH());
    assertNull(borders2.getInsideV());
}
Also used : TcPrInner(org.docx4j.wml.TcPrInner) TblBorders(org.docx4j.wml.TblBorders) Tbl(org.docx4j.wml.Tbl) Test(org.junit.Test)

Example 2 with TblBorders

use of org.docx4j.wml.TblBorders in project Java-Tutorial by gpcodervn.

the class TableBordersTest method testTableBorderAbsence.

@Test
public void testTableBorderAbsence() throws Docx4JException {
    Tbl tbl = table("<table><tr><td>1</td></tr></table>");
    TblBorders borders = tbl.getTblPr().getTblBorders();
    assertEquals(STBorder.NONE, borders.getTop().getVal());
    assertEquals(STBorder.NONE, borders.getBottom().getVal());
    assertEquals(STBorder.NONE, borders.getLeft().getVal());
    assertEquals(STBorder.NONE, borders.getRight().getVal());
    assertEquals(STBorder.NONE, borders.getInsideH().getVal());
    assertEquals(STBorder.NONE, borders.getInsideV().getVal());
    TcPrInner.TcBorders borders2 = ((Tc) ((Tr) tbl.getContent().get(0)).getContent().get(0)).getTcPr().getTcBorders();
    assertNull(borders2.getTop());
    assertNull(borders2.getBottom());
    assertNull(borders2.getLeft());
    assertNull(borders2.getRight());
    assertNull(borders2.getInsideH());
    assertNull(borders2.getInsideV());
}
Also used : TcPrInner(org.docx4j.wml.TcPrInner) TblBorders(org.docx4j.wml.TblBorders) Tbl(org.docx4j.wml.Tbl) Test(org.junit.Test)

Example 3 with TblBorders

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

the class Docx4J_简单例子 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 4 with TblBorders

use of org.docx4j.wml.TblBorders 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 5 with TblBorders

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

the class Docx4j_工具类_S3_Test method setTblBorders.

/**
 * @Description:表格增加边框 可以设置上下左右四个边框样式以及横竖水平线样式
 */
public void setTblBorders(TblPr tblPr, CTBorder topBorder, CTBorder rightBorder, CTBorder bottomBorder, CTBorder leftBorder, CTBorder hBorder, CTBorder vBorder) {
    TblBorders borders = tblPr.getTblBorders();
    if (borders == null) {
        borders = new TblBorders();
        tblPr.setTblBorders(borders);
    }
    if (topBorder != null) {
        borders.setTop(topBorder);
    }
    if (rightBorder != null) {
        borders.setRight(rightBorder);
    }
    if (bottomBorder != null) {
        borders.setBottom(bottomBorder);
    }
    if (leftBorder != null) {
        borders.setLeft(leftBorder);
    }
    if (hBorder != null) {
        borders.setInsideH(hBorder);
    }
    if (vBorder != null) {
        borders.setInsideV(vBorder);
    }
}
Also used : TblBorders(org.docx4j.wml.TblBorders)

Aggregations

TblBorders (org.docx4j.wml.TblBorders)18 TblPr (org.docx4j.wml.TblPr)10 CTBorder (org.docx4j.wml.CTBorder)9 BigInteger (java.math.BigInteger)8 Tbl (org.docx4j.wml.Tbl)6 Test (org.junit.Test)6 TcPrInner (org.docx4j.wml.TcPrInner)3 HashMap (java.util.HashMap)1 STBorder (org.docx4j.wml.STBorder)1