MS Word Automation - Combining word documents
-
Hi, I am working on a MS Word Automation project using VS2008 and Office 2003 in c# language. I have a One Page Word template which have bookmarks in table cells. These bookmarks are placeholders where specific information is put in from database using c#. I generate say 10 documents based on the template and save them as seperate file. What I would like is to have a 10 page single document. I can use selection.insertfile to create this document. When I do this, all the formatting goes bersek. Basically what i do is:
Word.Application app = new Word.Application( );
Word._Document wordDocument = app.Documents.Add(ref originalTemplate , ref oMissing , ref oMissing , ref oMissing); Word.Selection selection = app.Selection; int documentCount = MyGeneratedFiles.Length; int breakStop = 0; foreach (string file in MyGeneratedFiles) { breakStop++; // Insert the files to our template selection.InsertFile( file , ref oMissing , ref oMissing , ref oMissing , ref oMissing); try { if (breakStop != documentCount) selection.InsertBreak(ref pageBreak); } catch (Exception ex) { } } wordDocument = null; app.Visible = true;
This works as far as combining all documents is concerned. But the formattign goes crazy and there are no clearly defined pageBreaks. Is there a better way to combine multiple one page documents into one multi-page single document? I have been stuck on this for a while, any help will be much appreciated. Thank you