服务器上的文字自动化

发布于 2024-07-16 22:07:04 字数 466 浏览 1 评论 0原文

我们要求我们的网络应用程序能够进行邮件合并,并且 生成一些Word文档。 当然,这很容易使用 Word 自动化,但 Microsoft 不推荐 http://support.microsoft.com/kb/257757

“微软目前不推荐也不支持, Microsoft Office 应用程序在任何无人值守的情况下实现自动化, 非交互式客户端应用程序或组件(包括 ASP、 ASP.NET、DCOM 和 NT 服务),因为 Office 可能表现出不稳定 Office 在此环境中运行时的行为和/或死锁。”

在这种情况下人们通常会做什么?只需接受 Word 偶尔会挂起或寻求某些第三方解决方案。

We have a requirement that our web app will do a mail merge and
generate some Word documents. Of course this is very easy to do using
Word automation but is not recommended by Microsoft
http://support.microsoft.com/kb/257757.

"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."

What do people generally do in this situation? Just accept that Word
will occasionally hang or go for some third party solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稍尽春風 2024-07-23 22:07:04

基本上你有三个选择:

  1. 在服务器上运行它并接受这些后果。 根据经验,我知道事情确实会出错,但根据您正在执行的任务的实时性和优先级的高低,这可能是您可以忍受的事情。 基本上,如果您必须这样做,请尝试尽可能少地进行 Word 集成; 如果只是邮件合并,那么 99.9% 的情况下您可能不会遇到任何问题。
  2. 使用第三方解决方案。 但根据经验,除了非常简单的文档之外,这些文档永远无法很好地完成工作。 例如,如果您谈论的是从服务器上的 Word 文档生成 PDF 的东西,它看起来永远不会与 Word 中的一样。
  3. 不要直接调用 Word,而是使用 .NET Open XML 自己操作文档。 我什至用 VB6 编写过操作 Word/Excel 2007 文档的内容,因为它们都是文档记录良好的 XML 格式。 您必须使用2007 格式,但它又快又好。 但我认为像邮件合并之类的事情你必须手动完成,所以它可能不合适。 该解决方案通常更适合操作文档,而不是替换 Word API 函数。

从个人经验来看,我已经完成了第一个,并且效果很好,足以让我们的客户接受,第二个我搞砸了,但从未感到满意,而我已经完成了第三个,取得了巨大的成功(但需要相当多的工作)。

简而言之,人们会根据成本(时间等)与可靠性来采取各种措施:我建议选择 1 或 2 来获得快速(但不太可靠)的解决方案,或者选择 3 来获得更可靠(但成本较高)的解决方案。

Basically you have three choices:

  1. Run it on the server and accept those consequences. I know from experience that things do go wrong, but depending on how real-time and high priority the tasks you're doing are, it may be something you can live with. Basically if you have to do this, try to do as little Word integration as possible; if it's just a mail merge then you will probably get away without any problems 99.9% of the time.
  2. Use a third-party solution. But from experience, except for very simple documents, these never do the job quite properly. For example if you're talking about something that will generate PDFs from Word documents on the server, it will never look the same as it does in Word.
  3. Instead of directly invoking Word, use the .NET Open XML libraries to manipulate the documents yourself. I've even written stuff in VB6 that manipulates Word/Excel 2007 documents, since they're all in very-well documented XML formats. You have to use the 2007 formats, but it's fast and good. But something like a mail merge you'd have to do manually I think, so it may not be suitable. This solution is generally better for manipulating documents rather than replacing Word API functions.

From personal experience I've done the first and it worked well enough for our customer to accept, I messed around with the second and was never satisfied, and I've done the third with great success (but a fair bit of work).

In short, people do all sorts depending on cost (time etc) vs. reliability: I'd suggest option 1 or 2 for a fast (but less reliable) solution, or 3 for a more reliable (but costly) one.

酷到爆炸 2024-07-23 22:07:04

我使用自动化构建了一个 Powerpoint 应用程序。 基本上,它是一个幻灯片库网站,可以打开多个文件并将幻灯片移动到模板中。

我遇到的第一个问题是安全性,我最终将应用程序设置为以管理员身份运行,这是不推荐的,并且大多数地方可能会对此操作感到不满。 您需要灵活地自定义安全设置。

我确实经历了一些我们从未追踪到的应用程序池崩溃,而且我相信我还必须让用户始终登录到远程桌面,但始终断开连接。

最重要的是,你可以让自动化工作,但它很麻烦。 如果您有灵活性并且自动化是您最好的选择,那么就去做吧。 否则我有两个想法。

  1. Open XML 和 Open XML SDK 的使用
  2. 探索 受信任用户帐户上的 WCF 服务。 然后让您的网页调用或排队作业来处理请求。

I built a Powerpoint application using automation. Basically it was a Slide Library Website that opened multiple files and moved slides into a template.

The first issue I encountered was security, I ended up setting the application to run as administrator, which isn't recommended and most places would probably frown apon that action. You will need to have the flexibility to customize the security settings.

I did experience a few app pool crashes that we're never tracked down, and I believe I also had to have a user logged into the Remote Desktop, but disconnected, at all times.

Bottom line is you can get automation to work, but its hacky. If you have the flexibility and automation is your best bet then go for it. Otherwise I have two thoughts.

  1. Explore the use of Open XML and the Open XML SDK
  2. Look into running a WCF Sevice on a trusted user account. then have your webpage call out or queue a job for processing the request.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文