SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP and MS Word....

    Hey guys!

    Have a problem... hope to find a solution here

    I have a strSQL line.. that basically does a SELECT * from many joined tables. The output is displayed into a table. What I'd like to do is, to have each table's field entries (say a Name field) displayed as a URL.

    Clicking this URL will spawn an external viewer, which will open a predefined MS Word template. ASP code should then do a few SELECT statements, parse them, and write them to certain areas of the MS-Word document.

    Practically, a user should be able to click on a name, and have MS-Word launch, filling in details on the Word document, such as Name, Address, ZipCode and so on, which are stored in SQL-Server 2k.

    So. That's basically it.. any idea how I can get this to work? I know how to make the hyperlinks appear in each table cell, but after that it's a total blank

  2. #2
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, the link should go to an ASP script that will recieve the variables you pass, connect to the DB, and grab the data you need. From there, set the content-type as "application/msword" and output your data in standard HTML format. Word will show the HTML as a standard word document, but with the HTML formatting you specify.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wes DeMoney:

    Could you give me more information on what you mentioned... "From there, set the content-type as "application/msword" and output your data in standard HTML format".

    Specifically, do you have a sample code that does this?

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (Wes, hope you don't mind me butting in!)

    Word 2000/XP (and perhaps 97 too) will quite happily load up an HTML document as if it were a real word document - but they have to be told that this is what you want.

    The first set is to use set the ContentType header of the page you are generating to the correct type for a Microsoft Word document. This is done by using the Response.ContentType property as follows:

    [VBS]Response.ContentType = "application/msword"[/VBS]

    From that point on, the browser believes that what it is receiving is the contents of a Word document, not HTML. When the pages has finished loading, the browser will hand it over to Word for editing, which is what we want.

    Next you need to deliver the content of the page - this doesn't need to be anything special at all, just a plain old HTML table, generated from the DB in the way that you would normally do! It may be worth developing this bit first so that you can easily see the output in a normal browser window. Once that looks right, all you have to do is add the ContentType line, and bingo! It's a prefilled Microsoft Word document!

    One final thing. You must make sure that the ContentType line is executed before you send any data to the browser, so put it as near the top of your code as you can, but make sure that your DB data-gathering code executes BEFORE this statement, otherwise any script errors that occur will crop up in Microsoft Word rather than the browser!!


    M@rco

  5. #5
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, everything M@rco said is right. And no, I don't mind you helping out.

  6. #6
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot guys... appreciate the help. Will now go and experiment with this...

    Last note... Marco, you mentioned the string "Response.ContentType = "application/msword". Is there a MS-KB or other URL article on other applications that will work in this method?

  7. #7
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, there's not a lot to it, so the articles I've come across tend to cover exactly waht you have already asked, and we have already answered. The ContentType of a document just tells the browser how to interpret the data it receives, so that it can decide whether it "knows" how to display it or not. That's all there is to it!

    Here's a function from my personal code library for you to use - it returns the MIME type (what you use for the ContentType) for a given file extension:

    [VBS]
    'returns the MIME type for a given extension
    Function GetMIMEType(extension)
    select case UCASE(extension)

    'Common documents
    case "TXT","TEXT","JS"
    sMIME = "text/plain"
    case "HTM","HTML","ASP","CGI","PL"
    sMIME = "text/html"
    case "PDF"
    sMIME = "application/pdf"
    case "RTF"
    sMIME = "text/richtext"
    case "XML"
    sMIME = "text/xml"
    case "WPD"
    sMIME = "application/wordperfect"
    case "WRI"
    sMIME = "application/mswrite"
    case "XLS","XLS3","XLS4","XLS5","XLW"
    sMIME = "application/msexcel"
    case "DOC"
    sMIME = "application/msword"
    case "PPT","PPS"
    sMIME = "application/mspowerpoint"

    'WAP/WML files
    case "WML"
    sMIME = "text/vnd.wap.wml"
    case "WMLS"
    sMIME = "text/vnd.wap.wmlscript"
    case "WBMP"
    sMIME = "image/vnd.wap.wbmp"
    case "WMLC"
    sMIME = "application/vnd.wap.wmlc"
    case "WMLSC"
    sMIME = "application/vnd.wap.wmlscriptc"

    'Images
    case "GIF"
    sMIME = "image/gif"
    case "JPG","JPE","JPEG"
    sMIME = "image/jpeg"
    case "PNG"
    sMIME = "image/x-png"
    case "BMP"
    sMIME = "image/bmp"
    case "TIF","TIFF"
    sMIME = "image/tiff"
    case "AI","EPS","PS"
    sMIME = "application/postscript"

    'Sound files
    case "AU","SND"
    sMIME = "audio/basic"
    case "WAV"
    sMIME = "audio/wav"
    case "RA","RM","RAM"
    sMIME = "audio/x-pn-realaudio"
    case "MID","MIDI"
    sMIME = "audio/x-midi"
    case "MP3"
    sMIME = "audio/mp3"
    case "M3U"
    sMIME = "audio/m3u"

    'Video/Multimedia files
    case "AVI"
    sMIME = "video/avi"
    case "MPG","MPEG"
    sMIME = "video/mpeg"
    case "QT","MOV","QTVR"
    sMIME = "video/quicktime"
    case "SWA"
    sMIME = "application/x-director"
    case "SWF"
    sMIME = "application/x-shockwave-flash"

    'Miscellaneous
    case "COM","EXE","DLL","OCX"
    sMIME = "application/octet-stream"
    case "PDB"
    sMIME = "chemical/x-pdb"
    case "ZIP"
    sMIME = "application/x-zip-compressed"

    'Unknown
    case else
    sMIME = "application/octet-stream"
    end select

    GetMimeType = sMIME
    End Function
    [/VBS]

    Use it like this:
    [VBS]
    FileExtension = Mid(FileName,InstrRev(FileName,".")+1)
    Response.ContentType = GetMimeType(FileExtension)
    [/VBS]

    Of course, there are plenty more MIME types out there which I have not included, but that lot should cover most that you come across.

    M@rco

  8. #8
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP Word & XML?

    Ok, I've changed the mime type to msword and my form opens up in Word. However because the form is quite long and complicated I've used HTML tables to format the output. In Word the tables look really ugly. I'd like to reformat my ASP code to use XML, so that when my document opens up in Word I have more control over the look.

    Does anybody have any examples or know of any site that has good examples?

  9. #9
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you just use HTML properties in your tables so that they will display correctly in Word? Set your borders, border colors, cellspacing and padding, background colors, fonts, and widths. Word *should* handle the HTML just like the browser does.

  10. #10
    SitePoint Zealot BlitzCraig's Avatar
    Join Date
    Mar 2001
    Location
    Louisville, KY
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Wes DeMoney
    Why don't you just use HTML properties in your tables so that they will display correctly in Word? Set your borders, border colors, cellspacing and padding, background colors, fonts, and widths. Word *should* handle the HTML just like the browser does.
    As an addendum, are you using Word 97 or 2000? From my experience, 97 is horrible when it comes to HTML rendering, while 2000 does a much better job.

    Also, funky table structures have been known to cause me problems, too, especially if you have a lot of COLSPAN's and ROWSPAN's in your table(s).

    My two cents' worth...
    Craig H. Rettig - Bitbucket Heaven
    To understand recursion, you must first understand recursion.

  11. #11
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The application will be used by a number of people 99%should have Word 2000.

    The HTML formatting makes the table look ok when printed, but I'd like to make use of some of Words functionality it I can.

    I'd like to lock the text in the form so that the user can't change it. There will be a number of response fields in the form that the user will need to complete. (Thus the reason that I want Word rather than PDF.) In Word, I can set up the questions as sections and then lock them. I was hoping to send those same codes into Word. I thought I'd have to use XML to format the fields. Am I making this too difficult, is there a better way?

    Bottom line what I want, have the user hit a web page and download a form. Protect certain areas of the form, while letting the user input data to other parts of the form. The form is then printed and handled hard copy (per customer requirements). THANKS

  12. #12
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Linking Office and the Web via Script

    Just found this article on MS

  13. #13
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Word & ASP

    Ok, I set up my .ASP page to render the mime type 'application/msword'. My application works well when the User has Word 2000. However Word 97 doesn't know how to render the codes - any of them.

    (Unfortunately, I found out that 50% of my users haven't upgraded to Office 2000 - like I thought)

    Does anybody have any idea how to render the document in Word 97 as well as Word 2000?

    I've looked at putting Office 2000 on one of the servers and creating the document there, and then having the user click a link to that document to open it. But Microsoft frowns on that.

    Any other ideas? The simplier the better!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •