jacob版本:jacob-1.15-M3-x64.dll
硬件环境:64位4 AMD tl CPU。
操作系统:windows server 2008。
COM:office2007。
环境:tomcat6.0
错误描述:
com.jacob.com.ComFailException: Invoke of: Open
Source: Microsoft Excel
Description: Microsoft Excel 不能访问文件“D:\1.xls”。 可能的原因有以下几个:? 文件名称或路径不存在。
? 文件正被其他程序使用。
? 您正要保存的工作簿与当前打开的工作簿同名。调用源码:
public static void excelToHtml(String xlsfile, String htmlfile) {
ActiveXComponent app = new ActiveXComponent("Excel.Application");
try
{
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
System.out.println("Dispatch excels = ");
Dispatch excel = Dispatch.invoke(
excels,
"Open",
Dispatch.Method,
new Object[] { xlsfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
System.out.println("Dispatch excels = Open");
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {
htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
System.out.println("Dispatch excels = SaveAs");
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
System.out.println("convert to html success");
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
ComThread.Release();
}
}出错行:程序运行到Open的时候抛出异常。
Dispatch excel = Dispatch.invoke(
excels,
"Open",
Dispatch.Method,
new Object[] { xlsfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch(); 文件路径绝对准确,在调用前用了new File(excel).exists()判断文件是不是存在。
而且直接从我的电脑中是能够打开文件的。
现在头绪很乱,换了2个jacob都是同样的现象。
jacob.jar已经放入tomcat的lib。jacob-1.15-M3-x64.dll已经放入tomcat的bin。
不知道问题出在什么地方,哪位大侠能够给个思路!
PS:发现一个奇怪的现象,换了2个jacob,页面重新用新的jacob.jar重新编译过。但是每次调用都提示需要jacob-1.15-M3-x64.dll,这里不知道是什么原因。换jacob的时候没有重新启动系统。
硬件环境:64位4 AMD tl CPU。
操作系统:windows server 2008。
COM:office2007。
环境:tomcat6.0
错误描述:
com.jacob.com.ComFailException: Invoke of: Open
Source: Microsoft Excel
Description: Microsoft Excel 不能访问文件“D:\1.xls”。 可能的原因有以下几个:? 文件名称或路径不存在。
? 文件正被其他程序使用。
? 您正要保存的工作簿与当前打开的工作簿同名。调用源码:
public static void excelToHtml(String xlsfile, String htmlfile) {
ActiveXComponent app = new ActiveXComponent("Excel.Application");
try
{
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
System.out.println("Dispatch excels = ");
Dispatch excel = Dispatch.invoke(
excels,
"Open",
Dispatch.Method,
new Object[] { xlsfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
System.out.println("Dispatch excels = Open");
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {
htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
System.out.println("Dispatch excels = SaveAs");
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
System.out.println("convert to html success");
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
ComThread.Release();
}
}出错行:程序运行到Open的时候抛出异常。
Dispatch excel = Dispatch.invoke(
excels,
"Open",
Dispatch.Method,
new Object[] { xlsfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch(); 文件路径绝对准确,在调用前用了new File(excel).exists()判断文件是不是存在。
而且直接从我的电脑中是能够打开文件的。
现在头绪很乱,换了2个jacob都是同样的现象。
jacob.jar已经放入tomcat的lib。jacob-1.15-M3-x64.dll已经放入tomcat的bin。
不知道问题出在什么地方,哪位大侠能够给个思路!
PS:发现一个奇怪的现象,换了2个jacob,页面重新用新的jacob.jar重新编译过。但是每次调用都提示需要jacob-1.15-M3-x64.dll,这里不知道是什么原因。换jacob的时候没有重新启动系统。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货