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

查看:129
本文介绍了在Server 2012 R2中自动化MS 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 interop来自动执行Office(主要是Open和SaveAs).该代码在使用数百种Windows和Office版本(包括32位和64位)的许多组合的数百个服务器上已经可靠地工作了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一起使用,但是尝试打开W​​ord文档失败:

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.

创建文件夹:(将System32替换为Syswow64,具体取决于您使用的是x86还是x64位版本)

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

C:\ Windows \ System32 \ config \ systemprofile \ AppData \ Local \ Microsoft \ Windows \ INetCac‌he C:\ Windows \ System32 \ config \ systemprofile \ Desktop

C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\INetCac‌he C:\Windows\System32\config\systemprofile\Desktop

最后也是最重要的一步!

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天全站免登陆