I need to set the outer border of a Apache POI XWPFTable table. I know the below command set insade border, but do not find way for setting outer border.
table.setInsideHBorder( XWPFBorderType.SINGLE, 4, 0, "FF0000");
Any help? Thanks in advance!
I find it:
CTTblPr tblpro = table.getCTTbl().getTblPr();
CTTblBorders borders = tblpro.addNewTblBorders();
borders.addNewBottom().setVal(STBorder.SINGLE);
borders.addNewLeft().setVal(STBorder.SINGLE);
borders.addNewRight().setVal(STBorder.SINGLE);
borders.addNewTop().setVal(STBorder.SINGLE);
//also inner borders
borders.addNewInsideH().setVal(STBorder.SINGLE);
borders.addNewInsideV().setVal(STBorder.SINGLE);
Maybe is it not what you exactly looking for, but it you what to copy border style from one table to another you can use this method:
private void copyTableBorderStyle(XWPFTable table, XWPFTable newTable) {
newTable.setInsideHBorder(table.getInsideHBorderType(), table.getInsideHBorderSize(), table.getInsideHBorderSpace(), table.getInsideHBorderColor());
newTable.setInsideVBorder(table.getInsideVBorderType(), table.getInsideVBorderSize(), table.getInsideVBorderSpace(), table.getInsideVBorderColor());
newTable.getCTTbl().setTblPr(table.getCTTbl().getTblPr());
newTable.getCTTbl().setTblGrid(table.getCTTbl().getTblGrid());
}
But for your question if you what to change outer border you need to get org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl property and configure it:
CTTbl cttbl = table.getCTTbl();
To remove all borders from table:
tab.getCTTbl().getTblPr().getTblBorders().getLeft().setVal(STBorder.NONE);
tab.getCTTbl().getTblPr().getTblBorders().getRight().setVal(STBorder.NONE);
tab.getCTTbl().getTblPr().getTblBorders().getTop().setVal(STBorder.NONE);
tab.getCTTbl().getTblPr().getTblBorders().getBottom().setVal(STBorder.NONE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With