国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

word ppt excel文檔轉換成pdf

2019-11-15 02:26:11
字體:
來源:轉載
供稿:網友

Word PPT Excel文檔轉換成pdf

1.把word文檔轉換成pdf

(1).添加引用

1 using Microsoft.Office.Interop.Word;
添加引用

(2).轉換方法

 1 /// <summary> 2     /// 把Word文件轉換成pdf文件 3     /// </summary> 4     /// <param name="sourcePath">需要轉換的文件路徑和文件名稱</param> 5     /// <param name="targetPath">轉換完成后的文件的路徑和文件名名稱</param> 6     /// <returns>成功返回true,失敗返回false</returns> 7     public static bool WordToPdf(string sourcePath, string targetPath) 8     { 9         bool result = false;10         WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;//轉換格式1.wdExportFormatPDF轉換成pdf格式 2.wdExportFormatXPS轉換成xps格式11         object missing = Type.Missing;12         Microsoft.Office.Interop.Word.applicationClass applicationClass = null;13         Document document = null;14         try15         {16             applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();17             object inputfileName = sourcePath;//需要轉格式的文件路徑18             string outputFileName = targetPath;//轉換完成后PDF或XPS文件的路徑和文件名名稱19             WdExportFormat exportFormat = wdExportFormatPDF;//導出文件所使用的格式20             bool openAfterExport = false;//轉換完成后是否打開21             WdExportOptimizeFor wdExportOptimizeForPRint = WdExportOptimizeFor.wdExportOptimizeForPrint;//導出方式1.wdExportOptimizeForPrint針對打印進行導出,質量較高,生成的文件大小較大。2.wdExportOptimizeForOnScreen 針對屏幕顯示進行導出,質量較差,生成的文件大小較小。22             WdExportRange wdExportAllDocument = WdExportRange.wdExportAllDocument;//導出全部內容(枚舉)23             int from = 0;//起始頁碼24             int to = 0;//結束頁碼25             WdExportItem wdExportDocumentContent = WdExportItem.wdExportDocumentContent;//指定導出過程中是否只包含文本或包含文本的標記.1.wdExportDocumentContent:導出文件沒有標記,2.導出文件有標記26             bool includeDocProps = true;//指定是否包含新導出的文件在文檔屬性27             bool keepIRM = true;//28             WdExportCreateBookmarks wdExportCreateWordBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;//1.wdExportCreateNoBookmarks:不要在導出文件中創建書簽,2.wdExportCreateHeadingBookmarks:標題和文本框導出的文件中創建一個書簽,3.wdExportCreateWordBookmarks每個字的書簽,其中包括除包含頁眉和頁腳中的所有書簽導出的文件中創建一個書簽。29             bool docStructureTags = true;30             bool bitmapMissingFonts = true;31             bool UseISO19005_1 = false;//生成的文檔是否符合 ISO 19005-1 (PDF/A)32             document = applicationClass.Documents.Open(ref inputfileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);33             if (document != null)34             {35                 document.ExportAsFixedFormat(outputFileName, exportFormat, openAfterExport, wdExportOptimizeForPrint, wdExportAllDocument, from, to, wdExportDocumentContent, includeDocProps, keepIRM, wdExportCreateWordBookmarks, docStructureTags, bitmapMissingFonts, UseISO19005_1, ref missing);36             }37             result = true;38         }39         catch40         {41             result = false;42         }43         finally44         {45             if (document != null)46             {47                 document.Close(ref missing, ref missing, ref missing);48                 document = null;49             }50             if (applicationClass != null)51             {52                 applicationClass.Quit(ref missing, ref missing, ref missing);53                 applicationClass = null;54             }55         }56         return result;57     }
方法
 1     /// <summary> 2     /// 把Word文件轉換成pdf文件 3     /// </summary> 4     /// <param name="sourcePath">需要轉換的文件路徑和文件名稱</param> 5     /// <param name="targetPath">轉換完成后的文件的路徑和文件名名稱</param> 6     /// <returns>成功返回true,失敗返回false</returns> 7     public static bool WordToPdf(object sourcePath, string targetPath) 8     { 9         bool result = false;10         WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;11         object missing = Type.Missing;12         Microsoft.Office.Interop.Word.ApplicationClass applicationClass = null;13         Document document = null;14         try15         {16             applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();17             document = applicationClass.Documents.Open(ref sourcePath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);18             if (document != null)19             {20                 document.ExportAsFixedFormat(targetPath, wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 0, 0, WdExportItem.wdExportDocumentContent, true, true, WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missing);21             }22             result = true;23         }24         catch25         {26             result = false;27         }28         finally29         {30             if (document != null)31             {32                 document.Close(ref missing, ref missing, ref missing);33                 document = null;34             }35             if (applicationClass != null)36             {37                 applicationClass.Quit(ref missing, ref missing, ref missing);38                 applicationClass = null;39             }40         }41         return result;42     }
簡潔方法

(3).調用

1 OfficeToPdf.WordToPdf("d://1234.doc", "d://1234.pdf");
調用

2.把Excel文檔轉換成pdf

(1).添加引用

1 using Microsoft.Office.Interop.Excel;
添加引用

(2).轉換方法

 1     /// <summary> 2     /// 把Excel文件轉換成pdf文件 3     /// </summary> 4     /// <param name="sourcePath">需要轉換的文件路徑和文件名稱<
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 虹口区| 泽库县| 双柏县| 水富县| 改则县| 定南县| 特克斯县| 万源市| 泾阳县| 莫力| 东乌珠穆沁旗| 彭泽县| 日土县| 青州市| 姜堰市| 广德县| 三江| 富宁县| 浦北县| 玉山县| 文山县| 崇阳县| 文水县| 柘城县| 嘉峪关市| 昌乐县| 惠安县| 宁安市| 电白县| 嘉黎县| 平凉市| 昌吉市| 梓潼县| 北海市| 宜阳县| 平遥县| 句容市| 丰县| 万荣县| 灵宝市| 三门县|