[COMException (0x800a141f): Word 无法读取此文档。它可能是腐败的

[COMException (0x800a141f): Word was unable to read this document. It may be corrupt

Exception Details: System.Runtime.InteropServices.COMException: Word was unable to read this document. It may be corrupt. Try one or more of the following:

  • Open and Repair the file.
  • Open the file with the Text Recovery converter.] Microsoft.Office.Interop.Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible) +0

When running the solution through IIS on app server I'm getting this error. It's working fine in local. Tried both: changing Microsoft Word 97 - 2003 Document Authentication to none in DCOM Config and Interactive user permissions in security. And all required permissions are provided to the IIS user.

Considerations for server-side Automation of Office 声明如下:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

如果您想处理旧的 (doc) 文件格式,您需要使用专为服务器端执行而设计的组件。否则,您可以自由使用 Open XML SDK,请参阅 Getting started with the Open XML SDK 2.5 for Office 了解更多信息。

在应用服务器上将 IIS 用户添加为管理员解决了该问题。

参考下方 URL 在 windows 服务器上添加新的 user/admin。 https://social.technet.microsoft.com/wiki/contents/articles/13436.windows-server-2012-how-to-add-an-account-to-a-local-administrator-group.aspx

请确保该网站的帐号运行有足够的权限打开word文档。在IIS中,将应用程序使用的应用程序池的身份属性修改为LocalSystem.
此外,检查一些其他可能的原因。
https://www.systoolsgroup.com/updates/how-to-fix-word-was-unable-to-read-document-it-may-be-corrupt/
如果有进一步的进展,请随时告诉我。