使用jacob打印excel很简单,代码如下:
ActiveXComponent axc = null;
try {
ComThread.InitSTA();
axc = new ActiveXComponent("Excel.Application");
Dispatch.put(axc, "Visible", new Variant(false));
Dispatch workbooks = axc.getProperty("Workbooks").toDispatch();
Dispatch workbook = Dispatch.call(workbooks, "Open", fileFullPath,
new Integer(0), Boolean.FALSE).toDispatch();
Dispatch sheets = Dispatch.call(workbook, "Worksheets").toDispatch();
Dispatch sheet = Dispatch.call(sheets, "Item", new Integer(1))
.toDispatch();
Dispatch.call(sheet, "PrintOut", new Integer(beginPage), new Integer(endPage), new Integer(copys));
Dispatch.call(workbook, "Close", Variant.VT_FALSE);
} finally {
axc.invoke("Quit", new Variant[] {});
ComThread.Release();
}
然而,有时我们要设置纸张大小: