tags:

views:

320

answers:

3

I have a word document which is a blank form. I need to be able to fill it in programatically using .NET, and print out the result.

The form I have is a word document but I could obviously convert this to pdf if need be.

Can anyone please help?

Thanks

Ronnie

+1  A: 

Do you have Word document in Open XML format or is it in old binary format?

In Open XML this task can as easy as manipulation of XML inside a package (ZIP file).

If you have binary Word file this can be tricky. You will need to use .NET Programmability Support for Office and Microsoft.Office.Interop.Word namespace.

Jozef Izso
A: 

Are you working on the client-side or the server-side?

Client-side: start looking at Visual Studio Tools for Office.

Server-side: this one is difficult. My advice is don't run the client-side office libraries in a server environment. I'm working on this right now, and if you're in this boat, don't do it. Look for a client-side library.

jro
A: 

As Josef said, if it's OpenXML (Office 2007) document you can use the managed .net classes to easily update the document, which is basically modifying a bunch of xml files, zipped and renamed to .docx . Visual Studio tools for Office (VSTO) should help you out if need be for Office 2000 and 2003. For previous versions of office you'd need to use Office Automation COM Classes..

Now for updating fields in the word document, you'd need to identify where to insert text to. So if you have some bookmarks or markers to identify the places where you'd like to insert text... you can seek to that position and insert text. Printing the word doc should be simple since Word has printing support built in. Should be as easy as calling the right method.

Gishu
Thanks very much for all your responses. I've not implemented a solution yet, but I'm encouraged by some experimenting I've done - essentially saving the document as an xml file, and manipulating the xml before reopening it with Word.
Ronnie