473,378 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
3 4504
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sudha | last post by:
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
3
by: Phil Rutter | last post by:
Hello All, I have about 700 word documents that have 2 tables one is static 4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100 what i wolud like to do is open the word doc....
10
by: Neil | last post by:
An article at http://news.com.com/2100-1012-991694.html?tag=fd_top states: "XML would allow easier interchange of data generated in Office documents with back-end systems or existing Web...
0
by: sudha | last post by:
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
4
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
3
by: Dave | last post by:
I need to concatenate serveral text files into a larger file. I borrowed some code and patched together a batch file that runs in the command processor and looks like this: echo off chdir...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
5
by: Carstonio | last post by:
I use ASP to display links to Word documents on an intranet. Is there a way in ASP to do text searches on the documents' contents? I want the results to have the link to the Word document plus two...
5
by: Generic Usenet Account | last post by:
I have been to recreate a problem that I am having with strings with the trivial code snippet given below. In the trivial code example, I am reading five lines from a data file, each line having...
2
by: Derek Hart | last post by:
I am using late bound Microsoft Word integration with a vb.net winforms application. If I run code such as the following: Dim objWord As Object Dim objWrdDoc As Object Dim count As Integer...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.