concatenate word documents from .net

  • Thread starter Thread starter sudha
  • Start date Start date
S

sudha

Hi
I need to write a c# program which has to merge selected
word documents into one word document.
Kindly advise the efficient way to achieve this.
Thanks in advance
sudha
 
Hi Dino,

Do you have a particular reason for using the Selection object and
copy/pasting, rather than working directly with Word's Range object?
when I did this I used


Word.Application wordApp = new Word.Application();
wordApp.Visible= true; // for debug and monitoring
Word.Documents docs = wordApp.Documents;
Word.Document doc= docs.Open(ref filename1,
ref missing, // confirmconversions,
ref missing, // readOnly,
ref missing, // addtoRecentFiles,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDoc,
ref missing, // writePasswordTemplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialog);
);

wordApp.Selection.WholeStory();
wordApp.Selection.Copy(); // put on clipboard

docs.Close(ref missing, // savechanges
ref missing, // originalFormat
ref missing // RouteDocument
);

doc= docs.Open(ref filename2,
ref missing, // confirmconversions,
ref missing, // readOnly,
ref missing, // addtoRecentFiles,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDoc,
ref missing, // writePasswordTemplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialog);
);

wordApp.Selection.WholeStory();

wordApp.Selection.EndOf(ref missing, // Unit
ref missing // Extend
);

wordApp.Selection.InsertAfter("--------------------------------------------"
);
wordApp.Selection.InsertParagraph();
wordApp.Selection.Paste(); // paste from clipboard

-- Cindy
 
Back
Top