MS Word 2000 的 ColdFusion COM 对象操作在 100 秒后终止

发布于 2024-07-24 17:34:39 字数 1863 浏览 6 评论 0原文

我在Windows 2003 服务器上使用ColdFusion 7 来与使用COM 对象的Microsoft Word 2000 的默认安装进行对话。 目标是生成一个包含一些表格的文档。

我能做的就这么多了。 在此期间,CPU 峰值达到 100%,但我的代码可以正常运行,如果代码很短,它也可以工作。 我遇到的问题是当用于生成 Word 文档的代码达到大约 25kb+ 时(脚本生成大量重复代码)。

服务器花费 1 分 40 秒尝试生成文档后:

  • CPU 使用率降至 0(CPU 分配给 ColdFusion 的 jrun.exe 和 Word 2000 的 winword.exe)。
  • winword.exe 保留在内存中。
  • ColdFusion 的超时时间很长,因此客户端浏览器认为该页面仍在处理,但是...
  • 如果我杀死 winword.exe 进程,ColdFusion 立即向客户端返回错误。

所以这些较长的页面永远不会读完。 我尝试过很多变体。

  • ColdFusion 8 不起作用。
  • 使用 ColdFusion 7/8 的更新 JVM 不起作用。
  • 我正在运行的代码的内容没有区别。 我做了很多奇特的表格着色,但一百万行“Hello world”也消失了。
  • 令人惊讶的是,Word 2007 的试用确实有效。 格式有点奇怪,因为它默认为 Calibri 和其他新字体,但服务器将等待最多 7 分钟,直到完成。 然后重新启动服务器,尝试执行相同的代码,但 Word 2007 坚持认为它无法理解我发送给它的任何命令。 我已经完成了试用激活,甚至在重新启动后使用远程桌面启动了Word 2007。 第一次重启后,言语变得完全紧张。

我没有尝试过的:

  • Word 2003

除了 ColdFusion 领域的“这里是如何连接到 Word 的 API”和 ASP.NET 领域的“这里是如何将页数放入页脚”之外,我的网络搜索毫无结果。 似乎没有人使用 Adob​​e 的东西试图做到这一点,也没有人使用 Microsoft 的东西遇到我的问题。 于是我把自己抛到了你们的海岸上,流着血,营养不良,寻求对这个令人发狂的超时问题的深入了解。

ColdFusion 代码片段如下:

<cfset clientMatterCellStart = myDoc.Tables.Item(1).Cell(2,1)>
<cfset clientMatterCellEnd = myDoc.Tables.Item(1).Cell(2,7)>
<cfset clientMatterCellStart.Merge(clientMatterCellEnd)>
<cfset clientMatterCellStart.Range.Font.Bold = true>
<cfset clientMatterCellStart.Range.Font.Name = "Times New Roman">
<cfset clientMatterCellStart.Range.Font.Size = 14>
<cfset clientMatterCellStart.Range.ParagraphFormat.Alignment = 1><!--- Centered --->
<cfset clientMatterCellStart.Range.Text = "#MySubjects.subject_name[q]#">
<cfset clientMatterCellStart.Shading.BackgroundPatternColor = 13421772><!--- Grey 20% --->

I'm using ColdFusion 7 on a Windows 2003 server to talk to a default installation of Microsoft Word 2000 using COM objects. The goal is to generate a document with some tables in it.

That much I'm able to do. The CPU spikes to 100% for the duration, but my code is functional and if it's short, it works. The problem I'm encountering is when the code used to generate the Word document gets to be about 25kb+ (a script is generating lots of repetitious code).

After the server spends 1 minute 40 seconds trying to generate the document:

  • CPU usage drops to 0 (CPU was split between jrun.exe for ColdFusion and winword.exe for Word 2000).
  • winword.exe remains in memory.
  • ColdFusion's timeout is long, so the client browser thinks the page is still processing, however...
  • If I kill the winword.exe process, ColdFusion immediately returns an error to the client.

So these longer pages never finish. I've tried many variations.

  • ColdFusion 8 doesn't work.
  • Using an updated JVM for ColdFusion 7/8 doesn't work.
  • The content of the code I'm running makes no difference. I'm doing a lot of fancy table coloring, but a million lines of "Hello world" also dies.
  • A trial of Word 2007, amazingly, does work. The formatting is a little wonky, since it defaults to Calibri and the other new fonts, but the server will wait up to, say, 7 minutes until it's complete. And then reboot the server, try and execute the same code, and Word 2007 insists it doesn't understand any command I send it. I've done the trial activation, I've even started Word 2007 using remote desktop after the reboot. Word goes completely catatonic after that first restart.

What I haven't tried:

  • Word 2003

My net searches were fruitless beyond "here's how to connect to Word's API" in ColdFusion land and "here's how to put the page count in the footer" in ASP.NET land. It seems nobody using Adobe's stuff is trying to do this, and nobody using Microsoft's stuff is having my problem. And so I toss myself on your shores, bleeding and malnourished, seeking some insight into this maddening timeout problem.

Here's what a snippet of the ColdFusion code looks like:

<cfset clientMatterCellStart = myDoc.Tables.Item(1).Cell(2,1)>
<cfset clientMatterCellEnd = myDoc.Tables.Item(1).Cell(2,7)>
<cfset clientMatterCellStart.Merge(clientMatterCellEnd)>
<cfset clientMatterCellStart.Range.Font.Bold = true>
<cfset clientMatterCellStart.Range.Font.Name = "Times New Roman">
<cfset clientMatterCellStart.Range.Font.Size = 14>
<cfset clientMatterCellStart.Range.ParagraphFormat.Alignment = 1><!--- Centered --->
<cfset clientMatterCellStart.Range.Text = "#MySubjects.subject_name[q]#">
<cfset clientMatterCellStart.Shading.BackgroundPatternColor = 13421772><!--- Grey 20% --->

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

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

发布评论

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

评论(7

左耳近心 2024-07-31 17:34:39

好的,答案 2。既然 .Net weiners 说它有效,那么您可能会更幸运地通过外部 vb.net 脚本构建文档并通过配置文件和/或命令行参数传递任何特殊要求。 或者,如果您更喜欢真正的语言,您可以使用 win32com 模块在 python 中完成此操作。

简而言之,您的问题可能是 Coldfusion 有一个蹩脚的 COM 实现。

Ok, answer number 2. Since the .Net weiners say it works you might have more luck building the document via an external vb.net script and passing any special requirements via a configuration file and/or command-line arguments. Alternatively if you'd prefer a real language you could do it in python with the win32com module.

In short, your problem may be that Coldfusion has a crappy COM implementation.

无悔心 2024-07-31 17:34:39

我之前需要创建 MS Word 文档,并且做了很多研究来了解哪种方法是最好的。 最后我发现使用 MS Word 作为 COM 对象是一个非常非常糟糕的主意,主要是由于您提到的性能问题,但也由于它带来的安全问题。 这只是一个坏主意,而且绝对不会扩展到多个用户。

不过,我确实提出了另外两个可以接受的解决方案。 这是很久以前的事了,我身上已经没有代码了,但我会尽可能告诉你我能记得的内容。

  1. 我将一个word文档保存为word xml文档,在纯文本编辑器中打开它,将其拆开,然后使用ColdFusion自动生成我需要的内容。 这工作得很好,没有性能问题,但是拆开 xml 并弄清楚如何制作我需要的东西是乏味的,并且花费了一些时间。

  2. 我只是做了常规的 html,将报告设计得像网页一样漂亮,然后添加 cfheader 和 cfcontent 标记来告诉浏览器内容是一个 word 文档。 此选项有效,但我想我可能收到警告,附件的 Word 文档格式不正确,您是否仍要打开它? 在 MS Word 中打开它看起来很好,用户可以将其作为 doc 文件保存到桌面。

希望这可以帮助。

编辑:
抱歉,我的代码片段没有正确显示,这里是......

<cfheader name="content-disposition" value="attachment; filename=report.doc" />
<cfcontent type="application/msword" />

I had the need to create MS Word documents before and did much research into which is the best method to do it. In the end I found out that using MS Word as a COM object is a really, really bad idea, mostly notably due to the performance issues you mentioned, but also due to security issues it brings. It's just a bad idea and definitely will not scale up to multiple users.

However, I did come up with two other acceptable solutions. This was quite a while ago and I don't have the code with me anymore, but I'll tell you what I can remember as best I can.

  1. I saved a word document as word xml document, opened it in a plain text editor, took it apart, and used ColdFusion to auto generate what I needed. This worked well and there were no performance issues, but taking apart the xml and figuring out how to make what I needed was tedious and took some time.

  2. I just did regular html, designing the report to look nice as a web page and then added the cfheader and cfcontent tags to tell the browser the content was a word document. This option worked, but I think I may have gotton warnings that the attachment is not formatted correctly as a word document, do you want to open it anyway? Opening it appeared fine in MS Word and users could save it to the desktop as a doc file.

Hope this helps.

EDIT:
Sorry, my code snippet didn't appear correctly, here it is...

<cfheader name="content-disposition" value="attachment; filename=report.doc" />
<cfcontent type="application/msword" />
旧人哭 2024-07-31 17:34:39

尝试其他浏览器? 我遇到过 IE 过早断开长连接的麻烦(无论 CF 请求超时设置如何)。 它似乎认为长请求意味着服务器已损坏,因此它会中止(即使延迟的原因是因为它仍在上传文件)。

Try another browser? I've had my share of trouble with IE dropping long connections prematurely (regardless of the CF requesttimeout setting). It seems to think long requests mean the server is broken so it aborts (even when the reason for the delay is because it's still uploading a file).

情话墙 2024-07-31 17:34:39

我不认为将 HTML 转换为 PDF 而不是 Word 是一种选择?

I don't suppose converting the HTML to PDF instead of Word is an option?

ま柒月 2024-07-31 17:34:39

你可能是对的——你是一小群人,正在尝试做这类事情。

如果您可以选择编写 .Net 类或 Web 服务,那么这可能是一个不错的选择,因为听起来 ColdFusion 的 COM 实现还有一些不足之处。

考虑您的流程并尝试重构创建文档的代码部分,然后将其编写在 .Net 中并使用 ColdFusion 中的该类/服务。

You're probably right -- you're in a small group of people attempting to do this sort of thing.

If you have the option of writing a .Net class or webservice, that might be the way to go since it sounds like ColdFusion's COM implementation leaves something to be desired.

Think about your process and try to refactor the portion of your code that creates the document, then write it in .Net and use that class/service from ColdFusion.

夜吻♂芭芘 2024-07-31 17:34:39

我完全同意这里每个人的说法,COM 是一个坏主意。

值得一提的是,我使用 Coldfusion 生成的带有 CSS 样式表的 HTML 文件将很长(数百页)且相当复杂的文档转换为 Word,取得了良好的效果。

只需将它们提供给 Word:

<cfcontent type="application/msword" file="#filename#" deletefile="Yes" />

I totally agree with everybody here saying that COM is a bad idea.

For what it is worth I've had good results converting very long - hundreds of pages - and rather complex documents to Word using Coldfusion-generated HTML files with CSS stylesheets.

Just serve them to Word with:

<cfcontent type="application/msword" file="#filename#" deletefile="Yes" />
失与倦" 2024-07-31 17:34:39

我在使用 ColdFusion 和 COM 时也遇到过问题(我们使用它来使用 Word 和 PPT 并转换为 HTML)。 我认为您最好编写一个 .aspx 页面或 .NET Web 服务并传递所需的信息。 如果您打算进行更多的 MS Office 文档操作,有一个付费解决方案值得关注:
http:// /www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx

我们已经将它们用于 PPT 文件,并且非常高兴。

I've had my share of problem with ColdFusion and COM as well (we were using it to consume word and PPT and convert to HTML). I think you're better off writing an .aspx page or a .NET web service and passing in the information needed. If you're going to plan on doing more MS Office document manipulation, there's a for pay solution worth looking at:
http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx

We've used them for PPT files and have been very happy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文