我正在尝试通过 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())
我还差得很远。
谁能给我一个提示我在这里缺少什么,好吗?谢谢