欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
JCom調用COM組件把office文檔轉換為pdf
主要參考的是http://www.cnblogs.com/luckyxiaoxuan/archive/2012/06/13/2548510.html
轉word的代碼如下:
public void word2PDF(String inputFile, String pdfFile) {
        ReleaseManager rm = null;
        IDispatch app = null;
        try {
            rm = new ReleaseManager();
            app = new IDispatch(rm, "Word.Application");// 啟動(dòng)word
            app.put("Visible", false); // 設置word不可見(jiàn)
            IDispatch docs = (IDispatch) app.get("Documents"); // 獲得word中所有打開(kāi)的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開(kāi)文檔
            doc.method("SaveAs", new Object[] { pdfFile, 17 });// 轉換文檔為pdf格式
            doc.method("Close", new Object[] { false });
            app.method("Quit", null);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                app = null;
                rm.release();
                rm = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

參考文獻:
http://msdn.microsoft.com/en-us/library/office/ff198122%28v=office.15%29.aspx
http://msdn.microsoft.com/en-us/library/office/bb241296%28v=office.12%29.aspx

使用ExportAsFixedFormat方法而不是SaveAs方法,Excel的SaveAs方法不支持pdf。

代碼如下:
package main; 
import java.io.File; 
import javax.xml.ws.Dispatch;
 
import jp.ne.so_net.ga2.no_ji.jcom.IDispatch;
import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelApplication;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelRange;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbook;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbooks;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheet;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheets;
 
public class JComConvertor {
 
    /**
     * JCom調用MS Office轉換word為PDF
     * 
     * @param inputFile
     *            doc文檔的絕對路徑
     * @param pdfFile
     *            輸出pdf文檔的絕對路徑,例如D:\\folder\\test.pdf
     */
    public void word2PDF(String inputFile, String pdfFile) {
        ReleaseManager rm = null;
        IDispatch app = null;
        try {
            rm = new ReleaseManager();
            app = new IDispatch(rm, "Word.Application");// 啟動(dòng)word
            app.put("Visible", false); // 設置word不可見(jiàn)
            IDispatch docs = (IDispatch) app.get("Documents"); // 獲得word中所有打開(kāi)的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開(kāi)文檔
            doc.method("SaveAs", new Object[] { pdfFile, 17 });// 轉換文檔為pdf格式
            doc.method("Close", new Object[] { false });
            app.method("Quit", null);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                app = null;
                rm.release();
                rm = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    /**
     * JCom調用MS Office轉換excel為HTML
     * 
     * @param inputFile
     *            源文件絕對路徑
     * @param htmlFile
     *            目標文件絕對路徑
     */
    public void excel2HTML(String inputFile, String htmlFile) {
        ReleaseManager rm = null;
        IDispatch app = null;
        try {
            rm = new ReleaseManager();
            ExcelApplication ex = new ExcelApplication(rm);
            ex.put("Visible", false);
            IDispatch excs = (IDispatch) ex.get("Workbooks");
            IDispatch doc = (IDispatch) excs.method("Open", new Object[] {
                    inputFile, false, true });// 打開(kāi)文檔
            doc.method("SaveAs", new Object[] { htmlFile, 44 });
            doc.method("Close", new Object[] { false });
            ex.method("Quit", null);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                app = null;
                rm.release();
                rm = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    /**
     * JCom調用MS Office轉換Excel為PDF
     * 
     * @param inputFile
     *            源文件絕對路徑
     * @param htmlFile
     *            目標文件絕對路徑
     */
    public void excel2PDF(String inputFile, String pdfFile) {
        ReleaseManager rm = null;
        IDispatch app = null;
        try {
            rm = new ReleaseManager();
            ExcelApplication ex = new ExcelApplication(rm);
            ex.put("Visible", false);
            IDispatch excs = (IDispatch) ex.get("Workbooks");
            IDispatch doc = (IDispatch) excs.method("Open", new Object[] {
                    inputFile, false, true });// 打開(kāi)文檔
            doc.method("ExportAsFixedFormat", new Object[] { 0, pdfFile });
            doc.method("Close", new Object[] { false });
            ex.method("Quit", null);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                app = null;
                rm.release();
                rm = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    /**
     * JCom調用MS Office轉換Powerpoint為PDF
     * 
     * @param inputFile
     *            源文件絕對路徑
     * @param pdfFile
     *            目標文件絕對路徑
     */
    public void powerpoint2PDF(String inputFile, String pdfFile) {
        ReleaseManager rm = null;
        IDispatch app = null;
        try {
            rm = new ReleaseManager();
            app = new IDispatch(rm, "PowerPoint.Application");// 啟動(dòng)word
            // app.put("Visible", false); // 設置word不可見(jiàn)
            IDispatch docs = (IDispatch) app.get("Presentations"); // 獲得word中所有打開(kāi)的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開(kāi)文檔
            doc.method("SaveAs", new Object[] { pdfFile, 32 });// 轉換文檔為pdf格式
            // doc.method("Close", new Object[] { false });
            app.method("Quit", null);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                app = null;
                rm.release();
                rm = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    /**
     * JCom調用MS Office轉換Powerpoint為JPG
     * 
     * @param inputFile
     * @param pdfFile
     */
    public void powerpoint2JPG(String inputFile, String jpgFile) {
        ReleaseManager rm = null;
        IDispatch app = null;
        try {
            rm = new ReleaseManager();
            app = new IDispatch(rm, "PowerPoint.Application");// 啟動(dòng)word
            // app.put("Visible", false); // 設置不可見(jiàn)
            IDispatch docs = (IDispatch) app.get("Presentations"); // 獲得word中所有打開(kāi)的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開(kāi)文檔
            doc.method("SaveAs", new Object[] { jpgFile, 17 });// 轉換文檔為pdf格式
            // doc.method("Close", new Object[] { false });
            app.method("Quit", null);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                app = null;
                rm.release();
                rm = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
仿百度文庫解決方案(三)——利用JCom調用MS Office或者Acrobat API轉換文檔為PDF
invoke 錯誤
office轉換成pdf
有了這些,你可以少傳 800 次文檔
Office 2016 正式推出: 反擊 Google Docs, 另有免費版本!
通過(guò)Office插件OffiSync同步MS Office和Google Docs | 谷奧——探尋谷歌的奧秘
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久