views:

269

answers:

2

Hi,

I'm working on an application that generates a relatively large amount of Word output. Currently, we're using Word Interop services to do the document creation, but it's quite slow, especially in older (pre-2007) versions of Office. We'd like to speed up the generation.

I haven't done a lot of profiling yet, but I'm pretty confident that the problem is that we're making tons of COM calls. I'm hoping that profiling will yield a subset of calls that are slower than the others, but my gut tells me that it's probably a question of COM overhead (or Word Interop overhead), and not just a few slow calls.

Also, the product can generate HTML output, and that process (a) is very fast, and (b) uses pretty much the same codepaths, just with a different subclass for the HTML-specific pieces of functionality. So I'm pretty sure that our algorithm isn't fundamentally slow.

So... I'm looking for suggestions for alternate ways to accelerate the generation of Word files.

We can't just rename the generated HTML files to .doc, and we can't generate RTF instead -- in both cases, important formatting information get lost, and in the RTF case, inlined graphics don't work robustly.

One of the approaches we're evaluating is programmatically generating and opening a Word file (via interop) from a template that has a macro that knows how to consume a flat file and create the requisite output. We're interested in feedback about that approach, as well as any other ideas for speeding things up.

Thanks,

-Patrick

+4  A: 

If you can afford it, I'd recommend Aspose.Words product. Very fast and Word does not need to be installed.

Also it's much easier to use then office interop.

Chris Persichetti
I'd love to use it, but the price tag is prohibitive for our particular needs -- our app is a desktop app, so that's $2500 / developer or so.
Patrick Linskey
Yeah I know what you mean. Takes a lot of arm twisting to get tools this expensive. One piece of code I wrote took me about 4 hrs to do, I suspect it would have taken me a week to get everything working right and at a slow speed. I feel we got our moneys worth.
Chris Persichetti
+1  A: 

Your macro approach is exactly how we sped up slow excel interop (using version 2003 i think).

We found (at least with excel) that much of the slowness was due to repeated individual calls via the interop. We started to bunch up commands (ie. format large ranges, and then change specific cells as required rather than formating each cell individually), and logically moved on to macros.

I think that the marco + template approach would happily translate.

Gregory
Cool... how did you deal with communicating data from your .NET app to the macro?
Patrick Linskey
From memory, we tried to push the data with the minimal number of interop calls. Perhaps if you are luck, you can push it in one block, and have your macro parse it out and do its business?
Gregory