我试图通过Apache POI(带有ooxml-schemas 1.1的3.12)将表插入XWPF docx。
我正在使用
CTTblWidth oWidth = oTable.getCTTbl().getTblPr().addNewTblW();
oWidth.setType(STTblWidth.PCT);
oWidth.setW(BigInteger.valueOf(iWidth));
设置表格的宽度。 通过反复试验iWidth = 5000似乎是一个合理的值。
我试图通过
动态获取页面宽度CTBody oBody = m_oDocx.getDocument().getBody();
if (!oBody.isSetSectPr()) oBody.addNewSectPr();
CTSectPr oSect = oBody.getSectPr();
if (!oSect.isSetPgSz()) oSect.addNewPgSz();
CTPageSz pageSize = oSect.getPgSz();
BigInteger oPageSize.getW();
但对于DINA4而言,这将返回值为11906,远远不够。 即使通过这样的方式减去边距:
oPageSize.getW().subtract(oSect.getPgMar().getRight()).subtract(oSect.getPgMar().getLeft())
我还远远不够。
任何人都可以给我一个提示,我在这里失踪了吗,拜托? 感谢
答案 0 :(得分:2)
而不是
oWidth.setType(STTblWidth.DXA);
使用
collections.defaultdict
STTblWidth.PCT用于指定宽度的五十分之一。
STTblWidth.DXA用于指定点的二十分之一的宽度。 72分是一寸。