调用Office接口,完成Excel和Doc转PDF

/*jadclipse*/// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.

package com.acconsys.utils;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class ExcelToPdf
{
    public static void excel2PDF(String excelPath,String tempPdfPath)
    {
        ActiveXComponent x1 = new ActiveXComponent("Excel.Application");
        try
        {
            x1.setProperty("Visible", false);
            Dispatch workbooks = x1.getProperty("Workbooks").toDispatch();
            Dispatch workbook = Dispatch.invoke(workbooks, "Open", 1, new Object[] {
                excelPath, new Variant(false), new Variant(false)
            }, new int[3]).toDispatch();
            Dispatch.invoke(workbook, "SaveAs", 1, new Object[] {
                tempPdfPath, new Variant(57), new Variant(false), new Variant(57), new Variant(57), new Variant(false), new Variant(true), new Variant(57), new Variant(true), new Variant(true), 
                new Variant(true)
            }, new int[1]);
            Variant f = new Variant(false);
            Dispatch.call(workbook, "Close", new Object[] {
                f
            });
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }finally{
        	x1.invoke("Quit", new Variant[0]);
        }
    }
    public static void main(String[] args) {
    	excel2PDF("D:\\矩阵接点表.xls","D:\\矩阵接点表.pdf");
	}

}


/*
	DECOMPILATION REPORT

	Decompiled from: D:\workspace\com.acconsys.capital.10\lib\ExcelToPdfUtil.jar
	Total time: 203 ms
	Jad reported messages/errors:
The class file version is 50.0 (only 45.3, 46.0 and 47.0 are supported)
Couldn't fully decompile method excel2PDF
Couldn't resolve all exception handlers in method excel2PDF
	Exit status: 0
	Caught exceptions:
*/

猜你喜欢

转载自blog.csdn.net/qq_25958999/article/details/80611980