excel 2 html

public class Excel2Html {

	public static void change2Html(String docfile, String htmlfile) {
		ActiveXComponent app = new ActiveXComponent("Excel.Application"); 
		try {
			app.setProperty("Visible", new Variant(false));
			Dispatch docs = app.getProperty("Workbooks").toDispatch(); 
			Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch(); 
			Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(44) }, new int[1]);
			Variant f = new Variant(false); 
			Dispatch.call(doc, "Close", f); 
		} catch (Exception e) {
			e.printStackTrace(); 
		} finally {
			app.invoke("Quit", new Variant[]{}); 
		}
	}

	public static void main(String[] args) {
		try {
			Excel2Html.change2Html("c:\\tmp\\jeans.xls", "c:\\tmp\\jeans"); 
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

}

 

你可能感兴趣的:(html,C++,c,C#,Excel)