C#, Word document

L

lsg

Hi,
Is there any possibility to write an application i C# to open a MS Word
document (doc, docx), find any form fields and fill them, save and print
modified (filled) document without Word installed? Or make that
application works with Word 2k, XP, 2003 version?
 
N

Nicholas Paldino [.NET/C# MVP]

Yes, but given that you want to span all of those versions, it will be
slightly difficult.

The reason is because microsoft only had primary interop assemblies for
versions of office back to XP. Because of this, you will have to create an
interop assembly to make the calls to Word 2k yourself.

Or, you could make all the calls late bound, through reflection,
although you might take a performance hit by doing so. However, it would
simplify making the same calls across different versions (assuming the
parameter signatures of the methods you are calling are the same).
 
W

Wallace Stephen

Create New Word Document

object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);


Open Word Document

object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @?E:\CCCXCXX\TestDoc.doc?;
oDoc = oWord.Documents.Open(ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

More operations about C# Word can be found here;
http://stephenchy520.blog.com/2011/03/29/full-control-ms-word-via-c/
Hi,
Is there any possibility to write an application i C# to open a MS Word
document (doc, docx), find any form fields and fill them, save and print
modified (filled) document without Word installed? Or make that
application works with Word 2k, XP, 2003 version?
On Sunday, November 25, 2007 9:18 AM Nicholas Paldino [.NET/C# MVP] wrote:
Yes, but given that you want to span all of those versions, it will be
slightly difficult.

The reason is because microsoft only had primary interop assemblies for
versions of office back to XP. Because of this, you will have to create an
interop assembly to make the calls to Word 2k yourself.

Or, you could make all the calls late bound, through reflection,
although you might take a performance hit by doing so. However, it would
simplify making the same calls across different versions (assuming the
parameter signatures of the methods you are calling are the same).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top