Set Outer Border of Apache POI XWPFTable table?

人盡茶涼 提交于 2020-03-01 04:03:37

问题


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!


回答1:


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);



回答2:


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();


来源:https://stackoverflow.com/questions/34092933/set-outer-border-of-apache-poi-xwpftable-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!