Commit 412e3c8b authored by 王炜's avatar 王炜

excel转换为pdf,并调整行列

parent 97136093
......@@ -107,9 +107,11 @@ public class WordToPdf {
*
* @param inFilePath
* @param outFilePath
* @param fitToPagesTall 所有行为一页
* @param fitToPagesWide 所有列为一页
* @return
*/
public static boolean excel2pdf(String inFilePath, String outFilePath) {
public static boolean excel2pdf(String inFilePath, String outFilePath,Object fitToPagesTall,Object fitToPagesWide) {
ActiveXComponent activeXComponent = new ActiveXComponent("Excel.Application");
activeXComponent.setProperty("Visible", false);
......@@ -117,6 +119,13 @@ public class WordToPdf {
Dispatch excels = activeXComponent.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.call(excels, "Open", inFilePath, false, true).toDispatch();
Dispatch currentSheet = Dispatch.get((Dispatch) excel,
"ActiveSheet").toDispatch();
Dispatch pageSetup = Dispatch.get(currentSheet, "PageSetup")
.toDispatch();
//Dispatch.put(pageSetup, "Zoom", 50);
Dispatch.put(pageSetup, "FitToPagesTall", fitToPagesTall);
Dispatch.put(pageSetup, "FitToPagesWide", fitToPagesWide);
Dispatch.call(excel, "ExportAsFixedFormat", 0, outFilePath);
Dispatch.call(excel, "Close", false);
activeXComponent.invoke("Quit");
......@@ -144,6 +153,7 @@ public class WordToPdf {
Dispatch pageSetup = Dispatch.get(currentSheet, "PageSetup")
.toDispatch();
Dispatch.put(pageSetup, "Orientation", new Variant(2));
//设置缩放,值为100或false
Dispatch.call(excel, "ExportAsFixedFormat", 0, outFilePath);
Dispatch.call(excel, "Close", false);
......@@ -175,14 +185,13 @@ public class WordToPdf {
public static void main(String[] args) throws Exception {
// String jacobDllPath = "D:\\ideaProjects\\leaf-hlcm\\src\\main\\webapp\\WEB-INF\\server-script\\jacob\\jacob-1.18-x64.dll";
// System.setProperty("jacob.dll.path", jacobDllPath);
// System.setProperty("com.jacob.debug", "true");
String jacobDllPath = "E:\\idea_workspace\\leaf-hlcm\\src\\main\\webapp\\WEB-INF\\server-script\\jacob\\jacob-1.19-x64.dll";
System.setProperty("jacob.dll.path", jacobDllPath);
System.setProperty("com.jacob.debug", "true");
// word2pdf("D:\\u01\\hls_file\\excel\\8F5D12B0B1504518928FDD193C67A0A5con28168",
// "D:\\hand-Prpjects\\融资租赁合同文本-4pdf.pdf");
// cutPdf("D:\\\\hand-Prpjects\\\\付款请求书打印.pdf");
// excel2pdf("D:\\work\\leafProjects\\YondaTl\\src\\test.xlsx",
// "D:\\work\\leafProjects\\YondaTl\\src\\付款通知书NEW.pdf");
excel2pdf("C:\\Users\\Administrator\\Desktop\\对账单(白云BJJ22120045).xlsx", "C:\\Users\\Administrator\\Desktop\\c.pdf",1,1);
// excel2pdfOrientation("D:\\work\\leafProjects\\YondaTl\\src\\test.xlsx",
// "D:\\work\\leafProjects\\YondaTl\\src\\付款通知书NEW.pdf");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment