源代碼網(wǎng)絡(luò)上有很多,但是使用過程中發(fā)現(xiàn)問題還是有的,尤其是在文檔屬性配置不同的時候,出現(xiàn)的問題就是不能轉(zhuǎn)換。在開發(fā)端沒有問題,但在不同于開發(fā)端電腦的配置情況下,會出現(xiàn)意向不到的問題。此處對解決方案進行記錄。
using Word = Microsoft.Office.Interop.Word;
? public static bool ?WordToPdf(object sourcePath, string targetPath)
? ? ? ? {
? ? ? ? ? ? bool result = false;
? ? ? ? ? ? Word.WdExportFormat wdExportFormatPDF = Word.WdExportFormat.wdExportFormatPDF;
? ? ? ? ? ? object missing = Type.Missing;
? ? ? ? ? ? Microsoft.Office.Interop.Word.ApplicationClass applicationClass = null;
? ? ? ? ? ? Microsoft.Office.Interop.Word.Document document = null;
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();
? ? ? ? ? ? ? ? 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);
? ? ? ? ? ? ? ? if (document != null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? document.ExportAsFixedFormat(targetPath, wdExportFormatPDF, false, Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Word.WdExportRange.wdExportAllDocument, 0, 0, Word.WdExportItem.wdExportDocumentContent, true, true, Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missing);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? result = true;
? ? ? ? ? ? }
? ? ? ? ? ? catch
? ? ? ? ? ? {
? ? ? ? ? ? ? ? result = false;
? ? ? ? ? ? }
? ? ? ? ? ? finally
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (document != null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? document.Close(ref missing, ref missing, ref missing);
? ? ? ? ? ? ? ? ? ? document = null;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (applicationClass != null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? applicationClass.Quit(ref missing, ref missing, ref missing);
? ? ? ? ? ? ? ? ? ? applicationClass = null;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return result;
? ? ? ? }
在啟動程序中輸入dcomcnfg命令,打開組件服務(wù),選定
?設(shè)置其標(biāo)識為啟動用戶,可以快速解決很多問題。
文章來源:http://www.zghlxwxcb.cn/news/detail-448226.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-448226.html
到了這里,關(guān)于Asp.net Core使用Microsoft.Office.Interop.Word轉(zhuǎn)換文檔的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!