Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Streaming .RTF to MS Word 1

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi, I have found a great bit of code that takes ASP script and streams it to a .doc file that is presented client side and a copy stored server side.

The problem is this is a hard coded page and to make this really useful I need some kind of user interface.

I have built a simple textarea and passed form variables into this code, see below and got the text on the end result but a block of text from a textarea is not going to give the flexibility that is required to produce a nicely formed letter. I really need to be able to add some basic functionality to change the font etc.

Does anyone have any thoughts on this type of issue? Thanks for looking.



Code:
<%@ Language=VBScript %>
<!--#include file="includes/connection.asp"-->
<%
   Dim sRTF, sConn, rs
   
   Response.Buffer = True

   'Create the file for the RTF
   Dim fso, MyFile, sFileName
   Set fso = CreateObject("Scripting.FileSystemObject")
   sFileName = "sample2.doc"
   Set MyFile = fso.CreateTextFile(Server.MapPath(".") & "\" & _
                                   sFileName, True)

   MyFile.WriteLine("{\rtf1")

   'Write the font table
   sRTF = "{\fonttbl {\f0\froman\fcharset0 Times New Roman;}" & _
          "{\f1\fswiss\fcharset0 Arial;}" & _
          "{\f2\fmodern\fcharset0 Courier New;}}"
   MyFile.WriteLine sRTF

   'Write the title and author for the document properties
   MyFile.WriteLine("{\info{\title Sample RTF Document}" & _
                    "{\author Microsoft Developer Support}}")

   'Write the document header and footer
   MyFile.WriteLine("{\header\pard\qc\brdrb\brdrs\brdrw10\brsp100" & _
                    "{\fs50 "&Request.Form("Header_Text")&"} \par}")

   MyFile.WriteLine("{\footer\pard\qc\brdrt\brdrs\brdrw10\brsp100" & _
                    "{\fs18 "&Request.Form("Header_Text")&"} \par}")

   'Connect to the database in read-only mode

   
Set connStr = Server.CreateObject("ADODB.Connection")
	connStr.Open "PROVIDER=SQLOLEDB;DATA SOURCE= SQLSERVER;UID=sa;PWD=xxxxx;DATABASE=xxxxxx"

   'Execute a query that returns ID, Product name and amount of sale

   qry =  "select * FROM wce_contact where firstname = '"&("tim")&"'"
Set rs = connStr.Execute(qry)
   Do While Not (rs.eof)
     
     'Write the "body" of the form letter
    
     MyFile.WriteLine   "\fs26\f1"   'Default font

     MyFile.WriteLine   "\pard"
     MyFile.WriteLine   "\par\par\par\par"
     MyFile.WriteLine   "\par RE: Order #" & rs.Fields("contact").Value
     MyFile.WriteLine   "\par"
     MyFile.WriteLine   "\par"
     MyFile.WriteLine   "\par " & rs.Fields("contact").Value & ", "
     MyFile.WriteLine   "\par"
     MyFile.WriteLine   "\par Thank you for your order on " & _
                        rs.Fields("contact").Value & _
                        ". Your order has been shipped: "
     MyFile.WriteLine   "\par"
     MyFile.WriteLine   "\par"

     MyFile.WriteLine   "\pard \li720 {\f2"
     MyFile.WriteLine   "\par \b Order Number \b0 \tab " & _
                        rs.Fields("contact").Value
     MyFile.WriteLine   "\par \b Shipped By \b0 \tab " & _
                        rs.Fields("contact").Value
     MyFile.WriteLine   "\par \b Shipped On \b0 \tab " & _
                        rs.Fields("contact").Value
     MyFile.WriteLine   "\par}"
    
     MyFile.WriteLine   "\pard"
     MyFile.WriteLine   "\par"
     MyFile.WriteLine   "\par "&Request.Form("Body_Text")&" \par"

     MyFile.WriteLine   "\pard {\fs18 \qc \i"
     MyFile.WriteLine   "\par Thank you for choosing Northwind Traders!"
     MyFile.WriteLine   "\par}"

     rs.MoveNext

     'Add a page break and then a new paragraph
     If Not(rs.eof) Then MyFile.WriteLine("\pard \page")

   Loop

   'Close the recordset and database
   rs.Close
   connStr.Close
   Set rs = Nothing
   Set connStr = Nothing
   
   'close the RTF string and file
   MyFile.WriteLine("}")
   MyFile.Close

   Response.Write _
        "<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=" & sFileName & """>"

%>
 
Thanks Foxbro, That's a great article. I'm not sure that i can get the bit i need from it though. I almost need a pre-built GUI that has all the font changing, italic / bold text and table building features, that can then enable me retrieve the .rtf code on my ASP page so i can then construct the document.

I have to give the user of the website an editor type screen, like a textarea but with font selection etc. If i can do taht i'll be a happy man. Thanks for your input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top