public static void uniteDoc(List fileList, String savepaths)
{
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) fileList.get(fileList.size()-1), new Variant(false), new Variant(true) },
new int[3] ).toDispatch();
//追加文件
for (int i = 0; i < fileList.size()-1; i++)
{
Dispatch.invoke(app.getProperty("Selection").toDispatch(),
"insertFile", Dispatch.Method, new Object[] {
(String) fileList.get(i), "",
new Variant(false), new Variant(false),
new Variant(false) },
new int[3] );
// Dispatch.call(Dispatch.call(objWord, "WordBasic").getDispatch(), "FileSaveAs", new Variant("c://1.doc")); }
//保存新的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代码
{
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) fileList.get(fileList.size()-1), new Variant(false), new Variant(true) },
new int[3] ).toDispatch();
//追加文件
for (int i = 0; i < fileList.size()-1; i++)
{
Dispatch.invoke(app.getProperty("Selection").toDispatch(),
"insertFile", Dispatch.Method, new Object[] {
(String) fileList.get(i), "",
new Variant(false), new Variant(false),
new Variant(false) },
new int[3] );
// Dispatch.call(Dispatch.call(objWord, "WordBasic").getDispatch(), "FileSaveAs", new Variant("c://1.doc")); }
//保存新的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代码
请问你是用jacob-1.17-M4-x86.dll?我M4的吗??