|
I have outputted 'Word'/Excel files in many ASP systems (including as receipts for a ECommerce system), it is a simply addition of two lines of code and works cross browser and OS's.
If you make up your page as you wish for it to be, keep in mind an A4 page is 600 pixels wide and that you will not be able to link to a stylesheet, so all css needs to be set in the page.
If you need images I would recommend using full url path, rather then a relative path.
Once you have viewed the page and are happy with how it looks, go into the page, and within the top of the page, before your HTML, and within ASP tags, add the following two lines
///
Response.AddHeader "Content-Disposition","attachment;filename=filename.doc"
Response.ContentType = "application/vnd.ms-word"
///
Replace 'filename' with whatever you wish to call the file, you can even give it a date, just close the speech marks and then use + between the date coding.
For example: "attachment;filename=report1-"+ISOSDate+".doc"
This would set the date via an external code and then place it dynamically as the page is created.
You can also make the filename dynamic, there are a lot of options.
For printing and logging, whilst you cannot force it to open Word, this will just generate a Save/Open dialog box in IE, a Save in other browsers.
You can place a button that links to this page which submits code on click to update your database. Alternatively you could use Javascript to call the browser inbuilt 'Print' option and combine it with calling this page, although without trying it, I would not be 100% sure if it would all work together.
If you did need to record it had been printed, you could look at a link the customer clicks after printing, to record the fact, linked to a simple update/insert script, depending on your database setup.
If you were only interested in Printing the document, you could simply generate a page laid out as the document, and then call Print via JS via a link and also then provide a downloaded version for the customer to save. This would give you a reasonably easy way to then record the file had been called and send to print, of course you can never 100% be sure it printed without the interaction of the user.
And of course, do not forget you can create a file with 'File Object', which would create a file and save it to the server, allowing you to make it available to save/open/print or email etc.
This is always handy when you want to email a file as it will save it to the server, where as the above code simply generates a Word version for Saving, the file itself does not actually exist as a Word document per sa.
I hope that helps, do feel free to send me a message if you would like anything clarifying.
|