1. 程式人生 > >POI匯出word設定頁面大小及邊距

POI匯出word設定頁面大小及邊距

/** ==========文件建立====開始======== */
CustomXWPFDocument docx = new CustomXWPFDocument();
// 設定頁面大小間距
CTDocument1 document = docx.getDocument();
CTBody body = document.getBody();
if (!body.isSetSectPr()) {
    body.addNewSectPr();
}
CTSectPr section = body.getSectPr();
if(!section.isSetPgSz()) {
    section.addNewPgSz();
} // 設定頁面大小 當前A4大小 CTPageSz pageSize = section.getPgSz(); pageSize.setW(BigInteger.valueOf(11907)); pageSize.setH(BigInteger.valueOf(16840)); pageSize.setOrient(STPageOrientation.PORTRAIT); WordUtil.setMargins(docx, 1620L, 1645L, 1440L, 1440L);// 設定 頁邊間距