2015-05-13 86 views
-4

我需要一個邊框到我的XWPFTableCell,如下表所示。如何添加邊框到XWPFTableCell

 **XXX Technologies** 

__________________
|名稱|性別|工資|
__________________
的Raji女性24000
拉維男06790

+0

你看到了嗎? http://obscuredclarity.blogspot.com/2011/12/set-background-color-and-add-border-to.html –

回答

1

您可以添加邊框您的細胞像下面

CTTc ctTc = cell.getCTTc(); 
CTTcPr tcPr = ctTc.getTcPr(); 
CTTcBorders border = tcPr.addNewTcBorders(); 

border.addNewBottom().setVal(STBorder.SINGLE); 
border.addNewRight().setVal(STBorder.SINGLE); 
border.addNewLeft().setVal(STBorder.SINGLE); 
border.addNewTop().setVal(STBorder.SINGLE); 
4
CTTc ctTc = cell.getCTTc(); 
// here is need to change... 
CTTcPr tcPr = ctTc.addNewTcPr(); 
CTTcBorders border = tcPr.addNewTcBorders(); 
border.addNewRight().setVal(STBorder.SINGLE); 
+0

你可以使用下面的代碼:(只需要添加addNewTcPr()) –

+0

這是工作我!謝謝! – Fzum

1

此方法允許你設置表格的邊框到你想要的顏色。

private static void setTableBorderColor(XWPFTable table, String color) { 

    table.getCTTbl().getTblPr().getTblBorders().getBottom().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getRight().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setColor(color); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setColor(color); 

    table.getCTTbl().getTblPr().getTblBorders().getRight().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getBottom().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setSz(BigInteger.valueOf(4)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setSz(BigInteger.valueOf(4)); 
} 
0

你可以使用這個輔助函數的風格整個表(改編自拉胡爾khanvani):

public static void tableSetBorders(
     XWPFTable table, 
     STBorder.Enum borderType, 
     int size, 
     int space, 
     String hexColor) { 

    table.getCTTbl().getTblPr().getTblBorders().getBottom().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getRight().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setColor(hexColor); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setColor(hexColor); 

    table.getCTTbl().getTblPr().getTblBorders().getRight().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getBottom().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setSz(BigInteger.valueOf(size)); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setSz(BigInteger.valueOf(size)); 

    table.getCTTbl().getTblPr().getTblBorders().getBottom().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getTop().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getLeft().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getRight().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideH().setVal(borderType); 
    table.getCTTbl().getTblPr().getTblBorders().getInsideV().setVal(borderType); 
}