最近在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;