views:

221

answers:

4

What is the recommended strategy for in code to splice a set of MS Word documents together into one?

Cheers

Nik

+1  A: 

Go look at the various SDKs available. This is much easier to do if you are using Word 2007, as the file is actually a zip file containing various XML documents. MS even has an SDK called "Open XML Format SDK 1.0" which provides strongly typed classes for working with the new office format.

Chris Lively
Thanks, but I cannot assume that only the current version of Word is being used, I need to support older versions as well, so I cannot go the DocX route.
niklassaers-vc
+1  A: 

http://www.codeproject.com/KB/aspnet/AppendWordDocuments.aspx

Or any of these: http://www.google.com/search?hl=en&q=append+microsoft+word+documents

Nick
Thanks, the codeproject.com project solved the problem, I'll use that as my template. :-) Great find. :-)
niklassaers-vc
A: 

If you are using Open XML (ie docx), there are 2 basic approaches to solving this problem:

The first is to do what is necessary so ids point to the correct relationship (eg for images, hyperlinks), and styles are defined etc. A good explanation of what you need to do can be found at http://blogs.msdn.com/ericwhite/archive/2009/02/05/move-insert-delete-paragraphs-in-word-processing-documents-using-the-open-xml-sdk.aspx

PowerTools implements that.

The second is to use altChunk: http://blogs.msdn.com/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx

plutext
A: 

Very easy to do with Aspose.Words.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-join-and-append-documents.html

It will properly combine styles, lists etc in the resulting document.

romeok