We have a website where users enter tower information. The information is then stored in an access database and an email is sent out to all people who need to know about the tower. I have a word template that we use to take with us to verify that the tower is there. I would like to populate part of the documents with the information gathered from the website. I would like to include this in the asp pages where it is entered in so that it is attached to the initial email. I have a .vbs that can do this but the code does not work in asp. I use bookmarks to insert the data in the .vbs. If anyone could give me any pointers on how to get this information into the template and save the template under another name so it can be emailed. Thank you in advance.
Inserting variable data into word document
Collapse
X
-
I would modify the 'template' ms word file and insert 'place holders' like [dataplace1] or [sFistName] into the specific locations where i want to insert data from the database, then save this file to a location on the server.
At this point, it's simply a matter of using the FileSystemObjec t in ASP to read the file line by line, replacing the 'place holders' and then saving the modified word document to a different location on the server, or under a different file name.
Some other resources & suggestions..
If you've got a .vbs that can do this - are you able to convert it into a registerable .dll? If so, you could register the .dll on the server and create an instance of it within your asp script, and then use it. (Set oMyObj = Server.CreateOb ject("your.acti vexobject"))
A couple of resources regarding on the fly .doc creation..
Hope this helps..
Sincerely,
MarkComment
-
Is there really a need to have it within Word? What I am asking is if you have a pre-formatted letter why can’t that be the body of the email that you are sending out?
I think you will be better served converting the Word document into the body of the email and auto sending the email out to your users.
Let us know the path you take we are here to help~Comment
-
Good post Mark (markrawlingson ) I was under the impression to use the (word.applicati on) object that you had to have Word installed on the server, I guess not. I like your first suggestion. I tend to like using the clever solutions first.
I would have not posted my comments if I read yours first. We must have started at the same time. You’re just faster then me </grin>.
Good work! And Very good solution!!Comment
-
Thanks CroCrew :) - I believe you do need to have word on the server to use the word.applicatio n object - But you don't need to use the word.applicatio n object at all in this case. You can if you like, but there are other options such as using a template .doc file, or using the response.conten ttype method and setting it to that of word. As you said, why load your server up with superfluous junk when you don't need to? (You and I have discussed this to a certain extent before.. IE: FrontPage extensions :P)Originally posted by CroCrewGood post Mark (markrawlingson ) I was under the impression to use the (word.applicati on) object that you had to have Word installed on the server, I guess not. I like your first suggestion. I tend to like using the clever solutions first.
I would have not posted my comments if I read yours first. We must have started at the same time. You’re just faster then me </grin>.
Good work! And Very good solution!!
Sincerely,
MarkComment
-
ACK!! You swore (FrontPage extensions)
Joking aside, if it were me I would uses your 'template/place holders/FileSystemObjec t' solution if I were determined to have a word document attached to my email. I just thought that is a very clever. But, if I truly did not need a Word attachment then I would just convert the Word document to be my mail body and call it good. Heck I could even format the mail body to be HTML and add color </grin>.
Anyway I bow down and give you the “Golden Keyboard” award for the day for your clever solution. But, you should be band for the rest of the day for swearing </grin>.
Thanks for the future tip!Comment
-
hahaha,
Sorry for the swear!
The most efficient way of going about it would definitely be putting it in the mail body - but it depends on the scenario. If I wanted a portable .doc file i could carry around with me on my jump drive and/or print off without mail header/footer junk in there, maybe I want to give the file itself to my secretary, boss, or clients and don't want to forward an email - or even in a situation where there's no mailing going on - like if you wanted to provide the document as a download to clients or back-end users in an admin section - this type of file generation is ideal under those circumstances. And word & excel files are mainly built up of HTML code anyway, so colour and font changing are as easy as writing a <font> tag or two - they even recognize header tags and css - which is handy. In essence, they're just wysiwyg applications without the web pages :P
As with anything you do in programming, how you go about doing it is entirely circumstantial.
I even wrote a function not too long ago that takes a file path as an argument and returns the contents of the file to a string. The files i input to the function are just .txt files, they're templates of system generated emails with place holders like [## sFirstName ##] in them so that after the function returns the file contents to my string variable, I can pass a few replace statements past it and fire it off in the email body. This way i'm not really authoring the email body in my code (i try to make my code as LEAN as possible.. helps especially with sifting through code looking for bugs)
Sincerely,
MarkComment
Comment