偶需用jacob来把excel文件转存为html,大虾们来帮帮偶呀!
偶需要把word和excel文件转存为html格式的
word的已经搞定,但是excel的怎么转呢?
应该和转化word的类似,但是除了把Word改成Excel,还要在哪个地方修改呢?
下面的是我转化word用的代码:
import com.jacob.com.*;
import com.jacob.activeX.*;
public class WordToHtml {
public WordToHtml() {
}
public static void main(String[] args) {
ActiveXComponent component = new ActiveXComponent("Word.Application");
String inFile = "d:\\my.doc";
String outFile = "d:\\doctemp.htm";
try {
component.setProperty("Visible", new Variant(false));
////////*******改了之后,报错在这一行,Documents要改成什么呢?
Object wordacc = component.getProperty("Documents").toDispatch();
////////**********************
Object wordfile = Dispatch.invoke(wordacc, "Open", Dispatch.Method,
new Object[] {inFile, new Variant(false),
new Variant(true)}, new int[1]).toDispatch();
Dispatch.invoke(wordfile, "SaveAs", Dispatch.Method, new Object[] {outFile,
new Variant(8)}, new int[1]);
Variant f = new Variant(false);
Dispatch.call(wordfile, "Close", f);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
component.invoke("Quit", new Variant[] {});
}
}
}
com.jacob.com.ComFailException: Can't map name to dispid
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.activeX.ActiveXComponent.getProperty(ActiveXComponent.java)
at ExcelToHtml.main(ExcelToHtml.java:13)
Press any key to continue...