国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
JCom調(diào)用COM組件把office文檔轉(zhuǎn)換為pdf
主要參考的是http://www.cnblogs.com/luckyxiaoxuan/archive/2012/06/13/2548510.html
轉(zhuǎn)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); // 設(shè)置word不可見
            IDispatch docs = (IDispatch) app.get("Documents"); // 獲得word中所有打開的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開文檔
            doc.method("SaveAs", new Object[] { pdfFile, 17 });// 轉(zhuǎn)換文檔為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();
            }
        }
    }

參考文獻(xiàn):
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調(diào)用MS Office轉(zhuǎn)換word為PDF
     * 
     * @param inputFile
     *            doc文檔的絕對(duì)路徑
     * @param pdfFile
     *            輸出pdf文檔的絕對(duì)路徑,例如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); // 設(shè)置word不可見
            IDispatch docs = (IDispatch) app.get("Documents"); // 獲得word中所有打開的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開文檔
            doc.method("SaveAs", new Object[] { pdfFile, 17 });// 轉(zhuǎn)換文檔為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調(diào)用MS Office轉(zhuǎn)換excel為HTML
     * 
     * @param inputFile
     *            源文件絕對(duì)路徑
     * @param htmlFile
     *            目標(biāo)文件絕對(duì)路徑
     */
    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 });// 打開文檔
            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調(diào)用MS Office轉(zhuǎn)換Excel為PDF
     * 
     * @param inputFile
     *            源文件絕對(duì)路徑
     * @param htmlFile
     *            目標(biāo)文件絕對(duì)路徑
     */
    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 });// 打開文檔
            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調(diào)用MS Office轉(zhuǎn)換Powerpoint為PDF
     * 
     * @param inputFile
     *            源文件絕對(duì)路徑
     * @param pdfFile
     *            目標(biāo)文件絕對(duì)路徑
     */
    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); // 設(shè)置word不可見
            IDispatch docs = (IDispatch) app.get("Presentations"); // 獲得word中所有打開的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開文檔
            doc.method("SaveAs", new Object[] { pdfFile, 32 });// 轉(zhuǎn)換文檔為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調(diào)用MS Office轉(zhuǎn)換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); // 設(shè)置不可見
            IDispatch docs = (IDispatch) app.get("Presentations"); // 獲得word中所有打開的文檔
            IDispatch doc = (IDispatch) docs.method("Open", new Object[] {
                    inputFile, false, true });// 打開文檔
            doc.method("SaveAs", new Object[] { jpgFile, 17 });// 轉(zhuǎn)換文檔為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();
            }
        }
    }
}

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

聯(lián)系客服