在业务实践中往往会遇到数据的导出,world可以最直观将实际情况反馈出来,有些固定描述页签不需要业务编写,那么我们可做固定world,将导出world和固定world进行合并,进行多个world合并,下面我是将N(4)个world进行合并,直接上代码
import com.aspose.words.Document;
import com.aspose.words.ImportFormatMode;
import com.aspose.words.ImportFormatOptions;
import com.aspose.words.SaveFormat;
public class testController {
public static void main(String[] args) {
String wendang1 = "E:/wendang1.doc";
String wendang2 = "E:/wendang2.doc";
String wendang3 = "E:/wendang3.doc";
String wendang4 = "E:/wendang4.doc";
String zhuanzhe1 = "E:/zhuanzhe1.doc";
String zhuanzhe2 = "E:/zhuanzhe2.doc";
String zuizhong = "E:/zuizhong.doc";
testMain(wendang1,wendang2,wendang3,wendang4,zhuanzhe1,zhuanzhe2,zuizhong);
}
/**
* world合并
* @param overhaulPage :文档一
* @param overhaulPicturePage :文档二
* @param pjManagerPage :文档三
* @param proprietorPage :文档四
* @param IntermediatePage :中间转折页【检修详情页、检修详情页(图片)】
* @param IntermediatePageSec :中间转折页2【中间转折页[检修详情页、检修详情页(图片)]、项目经理工程师签字页】
* @param finallyPage :最终生成页
*/
public static void testMain(String overhaulPage, String overhaulPicturePage, String pjManagerPage, String proprietorPage, String IntermediatePage, String IntermediatePageSec, String finallyPage) {
try {
Document doca = new Document(overhaulPage);
Document docb = new Document(overhaulPicturePage);
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setIgnoreHeaderFooter(true);
doca.appendDocument(docb, ImportFormatMode.USE_DESTINATION_STYLES,importFormatOptions);
doca.save(IntermediatePage, SaveFormat.DOCX);
Document docc = new Document(IntermediatePage);
Document docd = new Document(pjManagerPage);
ImportFormatOptions importFormatOptions2 = new ImportFormatOptions();
importFormatOptions2.setIgnoreHeaderFooter(true);
docc.appendDocument(docd, ImportFormatMode.USE_DESTINATION_STYLES,importFormatOptions2);
docc.save(IntermediatePageSec, SaveFormat.DOCX);
Document doce = new Document(proprietorPage);
Document docf = new Document(IntermediatePageSec);
docf.appendDocument(doce, ImportFormatMode.USE_DESTINATION_STYLES,importFormatOptions2);
docf.save(finallyPage, SaveFormat.DOCX);
} catch (Exception e) {
e.printStackTrace();
}
}
}
引用maven
<dependency> <groupId>com.luhuiguo</groupId> <artifactId>aspose-cells</artifactId> <version>23.1</version> </dependency> <dependency> <groupId>com.luhuiguo</groupId> <artifactId>aspose-words</artifactId> <version>23.1</version> </dependency>
测试准备:创建需要合并的文档wendang1.doc、wendang2.doc、wendang3.doc、wendang4.doc其中也要创建出两个world合并过程中使用到转折world,zhuanzhe1.doc、zhuanzhe2.doc,和最终合并结束得到的world,zuizhong.doc
四个文档中写了分别写了古诗春晓的内容,合并前的内容
最终得到的效果