/**
* 打印Excel
* @param path
* @param printerName
* @throws Exception
*/
public static void print(String path, String printerName)
throws Exception {
ComThread.InitSTA();
ActiveXComponent xl = new ActiveXComponent(“Excel.Application”);
try {
Dispatch workbooks = xl.getProperty(“Workbooks”).toDispatch();
Dispatch workbook = Dispatch.call(workbooks, “Open”, path).toDispatch();
Dispatch.callN(workbook, “PrintOut”, new Object[] {
Variant.VT_MISSING, Variant.VT_MISSING, new Integer(1),
new Boolean(false), printerName, new Boolean(true),
Variant.VT_MISSING, “” });
Dispatch.call(workbook, “Close”);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
xl.invoke(“Quit”, new Variant[] {});
ComThread.Release();
}
}
这是打印方法,我用main方法调用这个方法能成功的打印出来,但是用我页面调用(弄个button访问后台方法),就不能打印了,这是怎么回事?用jacob
ComThread.InitSTA();到这个就不往下面走了