消息筛选器显示应用程序正在使用中。 ((错误来自 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER))与word无法打开现有文件normal该如何解决

最近在c#操作word时,每次转换前便一直疯狂报错弹窗无法打开现有文件normal。报错提示为“消息筛选器显示应用程序正在使用中。 ((错误来自 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER))”。下方是源码:

 			object missing = System.Reflection.Missing.Value;
            Word.Application wordApp = new Word.Application();
            
            Word.Document wordDoc = new wordApp.Documents();
            try
            {
                wordDoc = wordApp.Documents.Open((object)wordPath, missing, missing, missing, missing, missing,
                               missing, missing, missing, missing, missing, missing, missing, missing, missing);
                //word另存为pdf

                wordDoc.ExportAsFixedFormat(outFpath + id + ".pdf", Word.WdExportFormat.wdExportFormatPDF
                    , false, Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Word.WdExportRange.wdExportAllDocument, 1, 1,
                    Word.WdExportItem.wdExportDocumentContent
                    , false, true, Word.WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, true, false, ref missing);
            }
            catch (Exception ex)
            {
                if (null != wordDoc)
                {
                    wordDoc.Close();
                }
                if (null != wordApp)
                {
                    wordApp.Quit();
                    wordApp = null;
                }
            }
            finally
            {
                if (null != wordDoc)
                {
                    wordDoc.Close();
                }
                if (null != wordApp)
                {
                    wordApp.Quit();
                    wordApp = null;
                }
            }

解决方式:只要把Word.Document新建对象的这行代码换成下面几行便可以正常了。

			Word.Document wordDoc = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
            wordDoc.SpellingChecked = false;//关闭拼写检查
            wordDoc.ShowSpellingErrors = false;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值