java实现excel文件转换成html文件

2012-12-04  付民 

转换代码:
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;


public class ExcelToHtml {
public static void excelToHtml(String xlsfile, String htmlfile) {
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
try {
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.invoke(
excels,
"Open",
Dispatch.Method,
new Object[] { xlsfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {
htmlfile, new Variant(44) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
} catch (Exception e) {
e.printStackTrace();
} finally {
app.invoke("Quit", new Variant[] {});
}
System.out.println("转换成功!");
}  
public static void main(String[] args) {
String paths = new String("F:\\test.xlsx"); //需要转换的excel文件
String savepaths = new String ("D:\\test.html");   //转换的html文件放在D盘下
excelToHtml(paths, savepaths);
}
}


转换后的结果:

866°/8640 人阅读/2 条评论 发表评论

熊志男  2012-12-04

看着不错,可以试验下


付民  2012-12-04

熊志男: 看着不错,可以试验下


登录 后发表评论