473,387 Members | 1,534 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,387 software developers and data experts.

Word.ApplicationClass

Hai,
Has any one used Microsoft Office Word in C# Application.
How can i combine two word files into a single word file
using the Word.Application and Word.Document classes.

I know how to autogenerate a word doc but how to combine two
existing documents into a single doc file.

Any Ideas | code samples ?

S.Kartikeyan
Nov 15 '05 #1
2 15913
I am trying to do the exact same thing. Have you had any luck with
it? I am trying to dynamically create a cover page and attach it to
the beginning of an existing document.

If I figure anything out I will post back to this thread.

Regards,
Eric

in*******@yahoo.com (S.Kartikeyan) wrote in message news:<6d**************************@posting.google. com>...
Hai,
Has any one used Microsoft Office Word in C# Application.
How can i combine two word files into a single word file
using the Word.Application and Word.Document classes.

I know how to autogenerate a word doc but how to combine two
existing documents into a single doc file.

Any Ideas | code samples ?

S.Kartikeyan

Nov 15 '05 #2
I finally figured this out. The sample code is below.

/// <summary>
/// Prepends the <code>newDocURI</code> document to the beginning
/// of the <code>originalDocURI</code> and saves the output as the
/// <code>outputFileURI</code>.
/// </summary>
/// <param name="originalDocURI">The original main document</param>
/// <param name="newDocURI">The new document, cover page, etc.
/// that you want to prepend to the beginning of the main
document</param>
/// <param name="outputFileURI">The combination output file</param>
/// <returns></returns>
public string prependDoc(string originalDocURI, string newDocURI,
string outputFileURI)
{
object oFirstDoc = originalDocURI;
object oOutputDoc = outputFileURI;
object oPageBreak = Word.WdBreakType.wdPageBreak;

try
{
Word.Application wordApp = new Word.Application();

Word.Document origDoc = wordApp.Documents.Open(ref oFirstDoc,
ref missing, ref oTrue, ref missing, ref missing, ref
missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
origDoc.Activate();
wordApp.Selection.InsertFile(newDocURI, ref missing, ref
oFalse,
ref oFalse, ref oFalse);
wordApp.Selection.InsertBreak(ref oPageBreak);
wordApp.ActiveDocument.SaveAs(ref oOutputDoc, ref missing, ref
missing,
ref missing, ref missing, ref missing, ref missing, ref
missing,
ref missing, ref missing, ref missing);
wordApp.ActiveDocument.Close(ref oFalse, ref missing, ref
missing);
return outputFileURI;
}
catch (Exception ex)
{
throw ex;
}
}

Regards,
Eric

er********@yahoo.com (Eric) wrote in message news:<8c**************************@posting.google. com>...
I am trying to do the exact same thing. Have you had any luck with
it? I am trying to dynamically create a cover page and attach it to
the beginning of an existing document.

If I figure anything out I will post back to this thread.

Regards,
Eric

in*******@yahoo.com (S.Kartikeyan) wrote in message news:<6d**************************@posting.google. com>...
Hai,
Has any one used Microsoft Office Word in C# Application.
How can i combine two word files into a single word file
using the Word.Application and Word.Document classes.

I know how to autogenerate a word doc but how to combine two
existing documents into a single doc file.

Any Ideas | code samples ?

S.Kartikeyan

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MSNEWS | last post by:
Hi I'm using the word.applicationclass within my vb.net application to convert some word documents to text files. Is there anyway I can disable macros whilst loading the document, in Word I...
3
by: selen | last post by:
Hello I add Microsoft Word 10.0 Object Library from reference com. and I am writing my code to create an instance of a Word application.My code is Word.ApplicationClass oWordApp = new...
3
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
1
by: Markusek Peter | last post by:
I got this error: Exception Details: System.Runtime.InteropServices.COMException: Server execution failed Source Error: Line 29: protected System.Web.UI.HtmlControls.HtmlGenericControl zzz;...
14
by: Alan T | last post by:
These are the codes I created a document: _WordApp = new Interop.Word.Application(); _WordApp.Visible = false; _WordDoc = new Document(); _Missing = System.Reflection.Missing.Value;
2
by: Alan T | last post by:
private Interop.Word.Application _wordApp; What is the differences betwenn _wordApp.Quit(...) and _wordApp.Application.Quit(...) ?
1
by: Shar Shar | last post by:
Hi All, Actually I want to use "Word.ApplicationClass" class for opening a word file. And do following things, 1) Open word file. 2) Insert text in bookmark field. 3) Print resultant file as...
1
by: inxanu | last post by:
First of all, I am unsure as to where to post it, so please let me know (or move it) to where it should be. I create an instance of word as follows Word.ApplicationClass wd = new...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.