java使用aspose.words实现Word拼接的功能

需求:需要将其他模块生成的各个word汇总成一个整的Word。

参考官方介绍地址:https://apireference.aspose.com/java/words/com.aspose.words/DocumentBuilder

public Document appendDocument(Document mainDoc, Document addDoc, boolean isPortrait) {
     //设置书签,指定文档拼接的位置 String bookmark
= "插入的位置"; DocumentBuilder builder = null; try { builder = new DocumentBuilder(mainDoc); BookmarkCollection bms = mainDoc.getRange().getBookmarks(); Bookmark bm = bms.get(bookmark); if (bm != null) { builder.moveToBookmark(bookmark, true, false); builder.writeln(); Node insertAfterNode = builder.getCurrentParagraph().getPreviousSibling(); WordsHandler.insertDocumentAfterNode(insertAfterNode, mainDoc, addDoc); }
       //设置纸张大小 builder.getPageSetup().setPaperSize(PaperSize.A4);
if (isPortrait) { //纵向纸张, builder.getPageSetup().setOrientation(Orientation.PORTRAIT); builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE); } else { //横向 builder.getPageSetup().setOrientation(Orientation.LANDSCAPE); builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE); } //builder.insertBreak(BreakType.PAGE_BREAK); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return mainDoc; }
 

猜你喜欢

转载自www.cnblogs.com/yin1361866686/p/9561006.html