jacob合并多个word文件和插入分页符
2013-05-22 12:31
555 查看
//批量多个word文件合并成一个word文件
public void uniteDoc(ArrayList fileList, String savepaths,ArrayList filenameList) {
if (fileList.size() == 0 || fileList == null) {
return;
}
//打开word
ActiveXComponent app = new ActiveXComponent("Word.Application");//启动word
try {
// 设置word不可见
app.setProperty("Visible", new Variant(false));
//获得documents对象
Object docs = app.getProperty("Documents").toDispatch();
//打开第一个文件
Object doc = Dispatch.invoke((Dispatch) docs,"Open",Dispatch.Method,new Object[] { (String) filenameList.get(0),
new Variant(false), new Variant(true) },new int[3]).toDispatch();
//追加文件
for (int i = 1; i < fileList.size(); i++) {
Dispatch.invoke(app.getProperty("Selection").toDispatch(),
"insertFile", Dispatch.Method, new Object[] {
(String) filenameList.get(i), "",
new Variant(false), new Variant(false),
new Variant(false) }, new int[3]);
Dispatch selection = Dispatch.get(app, "Selection").toDispatch();
//插入分页符
Dispatch.call(selection, "InsertBreak" , new Variant(7) );
}
//保存新的word文件
Dispatch.invoke((Dispatch) doc, "SaveAs", Dispatch.Method,
new Object[] {savepaths, new Variant(1) }, new int[3]);
Variant f = new Variant(false);
Dispatch.call((Dispatch) doc, "Close", f);
} catch (Exception e) {
throw new RuntimeException("合并word文件出错.原因:" + e);
} finally {
app.invoke("Quit", new Variant[] {});
}
}
public void uniteDoc(ArrayList fileList, String savepaths,ArrayList filenameList) {
if (fileList.size() == 0 || fileList == null) {
return;
}
//打开word
ActiveXComponent app = new ActiveXComponent("Word.Application");//启动word
try {
// 设置word不可见
app.setProperty("Visible", new Variant(false));
//获得documents对象
Object docs = app.getProperty("Documents").toDispatch();
//打开第一个文件
Object doc = Dispatch.invoke((Dispatch) docs,"Open",Dispatch.Method,new Object[] { (String) filenameList.get(0),
new Variant(false), new Variant(true) },new int[3]).toDispatch();
//追加文件
for (int i = 1; i < fileList.size(); i++) {
Dispatch.invoke(app.getProperty("Selection").toDispatch(),
"insertFile", Dispatch.Method, new Object[] {
(String) filenameList.get(i), "",
new Variant(false), new Variant(false),
new Variant(false) }, new int[3]);
Dispatch selection = Dispatch.get(app, "Selection").toDispatch();
//插入分页符
Dispatch.call(selection, "InsertBreak" , new Variant(7) );
}
//保存新的word文件
Dispatch.invoke((Dispatch) doc, "SaveAs", Dispatch.Method,
new Object[] {savepaths, new Variant(1) }, new int[3]);
Variant f = new Variant(false);
Dispatch.call((Dispatch) doc, "Close", f);
} catch (Exception e) {
throw new RuntimeException("合并word文件出错.原因:" + e);
} finally {
app.invoke("Quit", new Variant[] {});
}
}
相关文章推荐
- Jacob模板替换生成word文件、word合并、word转pdf文件
- jacob 操纵Microsoft Word 进行转移、拆分、合并、插入等操作 结合Freemarker将无所不能
- jacob合并几个word文件到一个word文件
- java-jacob操作word,往word中动态插入各种文件
- 合并word文档时,用Jacob 插入分节符以达到保持原来的页眉的一个可行方案
- 【jacob word】使用jacob,合并多个word为一个word文件
- Word插入文件 VBA 合并 文件
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- 利用模板导出文件(二)之jacob利用word模板导出word文件(Java2word)
- 使用Jacob合并Word文档并填充文档中的书签
- word怎么插入长分页符
- jacob 设置 插入word 的图片大小
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- 合并多个文章为一个word文件
- 在word中插入分页符,多出一行
- jacob生成word插入excel图表部署注意
- 经验总结java利用jacob操作word文件
- jacob 实现Office Word文件格式转换
- delphi操作word基类,插入表格,分页符,日期,页码,替换,图片