在 Server 2012 R2 中自动化 MS Word [英] Automating MS Word in Server 2012 R2

查看:28
本文介绍了在 Server 2012 R2 中自动化 MS Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请不要回复不要在服务器上自动化 Word 的一般建议,也不要回复有关如果您真的必须如何在服务器上自动化 Word"的 MS 网页链接.我知道这一点.

Firstly, please don't reply with the generic advice not to automate Word on a server or a link to the MS web page on "how to automate word on a server if you really must". I am aware of this.

我有一个进程作为 Windows 服务运行,并使用 .Net OLE 互操作来自动化 Office(主要是打开和另存为).这段代码已经在数百台使用 32 位和 64 位 Windows 和 Office 版本的多种组合的服务器上可靠地运行了 8 年,所以我很高兴该机制是可靠的.到目前为止...

I have a process which runs as a Windows service and uses .Net OLE interop to automate Office (mostly just Open and SaveAs). This code has worked reliably for 8 years on literally hundreds of servers using many combinations of Windows and Office versions, both 32 and 64 bit, so I am happy that the mechanism is reliable. So far...

使用 Server 2012 R2,它可以与 PowerPoint 和 Excel 配合使用,但无法打开 Word 文档:

With Server 2012 R2, it works with PowerPoint and Excel but fails trying to open a word document:

System.Runtime.InteropServices.COMException (0x800A16A0): 
  The file appears to be corrupted.
   at Microsoft.Office.Interop.Word.Documents.Open...

到目前为止我的观察可能相关也可能不相关:

My observations so far which may or may not be relevant:

  • 所有文档都失败
  • 在 Windows 8.1 中运行良好
  • 同样的问题在客户站点和我们的测试环境中都发生过,因此不太可能是纯粹的环境问题
  • 我的应用程序使用 .Net 3.5
  • 代码链接到 2003 Interop 程序集(显然,程序集绑定重定向支持更高的 Office 版本)
  • 我们已在 32 位和 64 位 Office 2013 上尝试过,结果相同,但未尝试过较早版本的 office
  • 无论服务是作为 LocalSystem 还是作为标准用户帐户运行都失败
  • 如果我们在前台运行服务进程(即直接双击可执行文件),问题就不会发生

显然,我仍有一些事情需要调查,但很想知道是否有人看到过这个特定问题,即使您还没有解决它.请注意,办公自动化存在许多困难和问题,因此除非您的症状与我的非常相似,否则您可能不会遇到相同的问题.

Obviously I still have things to investigate but interested to hear if anyone else has seen this specific problem even if you haven't solved it. Please note there are many difficulties and problems with office automation so unless your symptoms are very similar to mine, you probably don't have the same problem.

推荐答案

同样的问题,但现在已经完全解决了.

Same issues here but got this fully resolved now.

我将 Word 2013 与 Windows 2012 R2 Server 结合在一个服务进程中运行,该进程可以执行我想要的所有操作,而无需启动交互式会话.我用它来将文档转换为 PDF 文件.在 Windows 服务中,我托管了一个 WCF 服务.

I have a Word 2013 in combination with Windows 2012 R2 Server running in a service process which does everything I want without the need of a interactive session to be started. I use this to convert documents to PDF files. Inside the Windows service I host a WCF service.

创建文件夹:(根据您使用x86x64 位版本,将System32 替换为Syswow64)

Create folders: (replace System32 with Syswow64 depending of you use x86 or x64 bit edition)

C:WindowsSystem32configsystemprofileAppDataLocalMicrosoftWindowsINetCac‌heC:WindowsSystem32configsystemprofileDesktop

C:WindowsSystem32configsystemprofileAppDataLocalMicrosoftWindowsINetCac‌he C:WindowsSystem32configsystemprofileDesktop

最后也是最重要的一步!

Start - run - dcomcnfg.exe

打开属性 -> 组件服务 - DCOM 配置 - Microsoft Word 97 - 2003 文档(注意这里没有提到版本但没关系,Office 2013 将使用它作为 DCOM 配置)

Open properties -> Component Services - DCOM Config - Microsoft Word 97 - 2003 Document (Note that the version is not mentioned here but that does not matter Office 2013 will use this as DCOM config)

打开标签标识.将运行配置为本地管理员帐户.我做了一些测试,即使没有为用户启动交互式会话,Word 2013 也能正常工作.

Open tab Identity. Configure the run as a the local Administrator account. I did some tests Word 2013 will work just fine even if no interactive session is started for the user.

这篇关于在 Server 2012 R2 中自动化 MS Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆