今天刚用jacob 打印发票,网上说Orientation 设置为2 是横向,我设置了还是纵向打印,0 也试过,也是一样,请教大神
ComThread.InitSTA();
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
try {
// 不打开文档
Dispatch.put(xl, "Visible", new Variant(false));
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
// 打开文档
Dispatch excel = Dispatch.call(workbooks, "Open", f.getAbsolutePath()).toDispatch();
Dispatch sheets = Dispatch.get((Dispatch) excel, "Sheets").toDispatch();
Dispatch sheet = Dispatch
.invoke(sheets, "Item", Dispatch.Get, new Object[]{new Integer(sheelIndex+1)}, new int[1])
.toDispatch();
Dispatch pageSetup = Dispatch.get(sheet, "PageSetup").toDispatch();
Dispatch.put(pageSetup, "Orientation", new Variant(2));
Dispatch.call(sheet, "PrintOut");
// 开始打印
if (excel != null) {
// Dispatch.call(excel, "PrintOut");
// 增加以下三行代码解决文件无法删除bug
Dispatch.call(excel, "save");
Dispatch.call(excel, "Close", new Variant(true));
excel = null;
}
xl.invoke("Quit", new Variant[]{});
xl = null;
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
// 始终释放资源
ComThread.Release();
}
Dispatch.put(pageSetup, "Orientation", new Variant(2));
调试下这里,看pageSetup设置了没有