Home > Archive > C# > January 2006 > Word Document Generation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Word Document Generation
|
|
| Vincent A. 2006-01-10, 4:10 am |
| Hello all,
I'm looking for a simple method to auto generate word document with
data stored in a database. I find something which can help me, Ws
attachment, but i would not like using web services. Is it possible ?
Thanks in advance,
Vincent.
| |
| Bruce Wood 2006-01-10, 4:10 am |
| Warning: this probably isn't the Microsoft-approved way of doing this,
however...
I've always done it the quick and cheesy way, using RTF. This works
well if you're just creating large numbers of Word documents (or a
highly repetitive document, like a table of data) changing the data on
each one. Sort of a mailmerge type operation. If you want a multi-page
document then mock up at least three pages.
All I do is create a Word document the way I want it to look (in Word),
and then save it in RTF format. Since RTF is text, you can read it
easily, and edit it easily.
It's pretty easy to strip out all of the useless stuff at the beginning
of the RTF document that Word generates: just take out some stuff (like
font definitions), then open the document in Word again to see if it
looks OK. Strip the document down to the minimum RTF required in order
to produce the look you want.
Then, just grab the database data and write it at appropriate places
within the RTF stream. That is, just write a little program that
outputs "canned" text--the RTF from the Word document you created--and
inserts the database data at appropriate points. Your program will just
be a long sequence of write statements, writing some RTF, then some
data, then some RTF, etc.
The resulting document should open in Word and look the way you want it
to.
Cheap and nasty, but it works.
| |
| Vincent A. 2006-01-10, 4:10 am |
| Hello Bruce,
Thanks for your help !
I find something interresting without using rtf document. I find an
example on one forum which is named WordApplication but i lost the url.
Here is an article which deals with the subject but i find the example
not very simple :
http://www.dotnetguru.org/articles/.../WordFusion.htm
This example is using Ws_Attachment but i doesn't suceed in attaching a
picture ... If someone has an idea ?
Thanks
Vincent.
| |
|
|
|
|
|