Dynamically creating a Word document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to create a Word document that will display data from a database. I
don't want to create the file on the server, I just want to stream it out
directly to the user. When they click a button, the Word Save Open window
will open, and allow the user to Save or Open the document in Word. I know I
need to use response.binarywrite, but I don't know if it is possible to
create the binary object without first saving it to a temporary file. Would
I need to create a Word template, and how would I use it?

How would I get data from a data grid into this document?
 
Hi Leonard...

There IS a possibility of doing what you want with the most recents
versions of Word (i.e. from Office XP and above), but it has no
backwards compatibility.

You CAN simple set the ResponseType to "application/word" and send an
XML document that mimics the Word new XML document file type.

Just create a new document and save as an XML file and see the output.

Regards,

Paulo
 
Hi Paulo,
Does that mean I still have to create a file, enen if it is temporary? I
would create the file on my app server, and then use ResponseType
application/word to send it to the user, so the user would not need the
latest version, correct? So, I would need to create the word document, using
xml, and some text, but couldn't I just save to a .doc file?
 
You shouldn't have to create a temp file on the server side, some sites
do this for various reasons, but as long as you can create the file in
a file object of some kind (or even just store the file contents in a
variable), then you can stream the download to the requesting user.

Things to look at for this:

Dim fileName, fileContents

fileName = "myfile.doc"
fileContents = someFileContentsString

Response.ContentType = "application/word"
Response.AddHeader "content-disposition", "attachment; filename=" &
fileName
Response.Write fileContents
Response.End


We have this grouped in a procedure where we just pass in the filename
and the filecontents, you could expand to include the filetype to make
it more generic.
 
Back
Top