467,894 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

concatenate word documents from .net

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

Nov 22 '05 #1
  • viewed: 4281
Share:
3 Replies
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

// include this line to save the doc when finished.
// wordApp.Save();

// include this next line to close MS-Word
// wordApp.Quit(ref missing, ref missing, ref missing);

"sudha" <su*******@hotmail.com> wrote in message
news:09****************************@phx.gbl...
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

Nov 22 '05 #2
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

Nov 22 '05 #3
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

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by sudha | last post: by
3 posts views Thread by Phil Rutter | last post: by
10 posts views Thread by Neil | last post: by
4 posts views Thread by Daniel | last post: by
5 posts views Thread by Generic Usenet Account | last post: by
2 posts views Thread by Derek Hart | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.