473,790 Members | 2,850 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4539
when I did this I used
Word.Applicatio n wordApp = new Word.Applicatio n();
wordApp.Visible = true; // for debug and monitoring
Word.Documents docs = wordApp.Documen ts;
Word.Document doc= docs.Open(ref filename1,
ref missing, // confirmconversi ons,
ref missing, // readOnly,
ref missing, // addtoRecentFile s,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDo c,
ref missing, // writePasswordTe mplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialo g);
);

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

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

doc= docs.Open(ref filename2,
ref missing, // confirmconversi ons,
ref missing, // readOnly,
ref missing, // addtoRecentFile s,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDo c,
ref missing, // writePasswordTe mplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialo g);
);

wordApp.Selecti on.WholeStory() ;

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

wordApp.Selecti on.InsertAfter( "--------------------------------------------"
);
wordApp.Selecti on.InsertParagr aph();
wordApp.Selecti on.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(re f missing, ref missing, ref missing);

"sudha" <su*******@hotm ail.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.Applicatio n wordApp = new Word.Applicatio n();
wordApp.Visible = true; // for debug and monitoring
Word.Documents docs = wordApp.Documen ts;
Word.Document doc= docs.Open(ref filename1,
ref missing, // confirmconversi ons,
ref missing, // readOnly,
ref missing, // addtoRecentFile s,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDo c,
ref missing, // writePasswordTe mplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialo g);
);

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

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

doc= docs.Open(ref filename2,
ref missing, // confirmconversi ons,
ref missing, // readOnly,
ref missing, // addtoRecentFile s,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDo c,
ref missing, // writePasswordTe mplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialo g);
);

wordApp.Selecti on.WholeStory() ;

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

wordApp.Selecti on.InsertAfter( "--------------------------------------------"
);
wordApp.Selecti on.InsertParagr aph();
wordApp.Selecti on.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.Applicatio n wordApp = new Word.Applicatio n();
wordApp.Visible = true; // for debug and monitoring
Word.Documents docs = wordApp.Documen ts;
Word.Document doc= docs.Open(ref filename1,
ref missing, // confirmconversi ons,
ref missing, // readOnly,
ref missing, // addtoRecentFile s,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDo c,
ref missing, // writePasswordTe mplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialo g);
);

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

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

doc= docs.Open(ref filename2,
ref missing, // confirmconversi ons,
ref missing, // readOnly,
ref missing, // addtoRecentFile s,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDo c,
ref missing, // writePasswordTe mplate,
ref missing, // format,
ref missing, // encoding,
ref missing, // visible,
ref missing, // openAndRepair,
ref missing, // docDirection,
ref missing // noEncodingDialo g);
);

wordApp.Selecti on.WholeStory() ;

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

wordApp.Selecti on.InsertAfter( "--------------------------------------------"
);
wordApp.Selecti on.InsertParagr aph();
wordApp.Selecti on.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
359
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
4314
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. import the first word table then import the second word table close word doc open next word doc and repeat process. i am able to import one set of data currently into an excel spread sheet but how can i loop through all the documents and import them...
10
3062
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 services." As part of an Access 2000 application, I have to continually parse Word documents and store the parsings in Access tables using Automation to control Word and parse the document. Is there a way that XML would help with that? Thanks.
0
2412
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
7686
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 handle the automation. So, i'm using the following code to create a new word document: ---Code---
3
7756
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 C:\Documents and Settings\dave\My Documents\SQL\Deploy rem Create tables echo Generate CREATE TABLE SQL script ...
7
6251
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 user and populated (with info from an Access database) at run-time, then saved as Word documents. The program I have coded works fine -- it does what I need it to do. But it has two problems: (1) it runs very slowly, and (2) it does not seem to...
5
3116
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 or three lines from the document that include the search terms.
5
2808
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 only one word. I try to concatenate each word read into a string variable, separated by a delimiter character. Even though I am able to read the words from the file correctly, I am not able to correctly concatenate the string. I was expecting the...
2
4882
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 Dim filename As String filename = "c:\temp\mergedata\1.doc" objWord = CreateObject("Word.Application") For count = 1 To 10000
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.