利用jacob将Excel转换为PDF时,Excel中的列在PDF中显示不全.Excel的列有很多。
有什么方法可以改变纸张大小,或者缩小PDF内容?或者还要其他方法解决这个问题?
public boolean excelTopdf(String inputFile, String pdfFile){
ComThread.InitSTA();
ActiveXComponent app = new ActiveXComponent("Excel.Application");
app.setProperty("Visible", new Variant(false));
Object excels = app.getProperty("Workbooks").toDispatch();
Object excel = Dispatch.invoke(
(Dispatch) excels,
"Open",
Dispatch.Method,
new Object[] { inputFile, new Variant(false),
new Variant(true) }, new int[9]).toDispatch();
Dispatch currentSheet = Dispatch.get((Dispatch) excel,
"ActiveSheet").toDispatch();
Dispatch pageSetup = Dispatch.get(currentSheet, "PageSetup")
.toDispatch();
Dispatch.put(pageSetup, "Orientation", new Variant(2));
Dispatch.put(pageSetup, "Zoom", false); // 值为100或false
Dispatch.put(pageSetup, "FitToPagesWide", 1); // 所有列为一页(1或false)
Dispatch.call(currentSheet, "SaveAs", pdfFile,
new Variant(57));
if (app != null) {
app.invoke("Quit", new Variant[] {});
app = null;
}
ComThread.Release();
return true;
}