ASP to Microsoft Word Automation

Discussion in 'ASP General' started by JP SIngh, Jan 20, 2005.

  1. JP SIngh

    JP SIngh Guest

    HI All

    I just wonder if anyone has created a word document using ASP.

    I am able to create a work document with ASP without any problem but what I
    want to do is slightly more than I know. I am sure someone where will know
    how to do the following.

    We have a Word Template which is our standard contract type. I have some
    data stored my access database record. I want to merge the two together.
    i.e. take the data from access and insert into various points in the word
    document. The points where I need to insert the data is definded by
    Bookmarks in Word. This is how you can do it VBA but not sure if this is
    possible in ASP.

    In VBA I will write a statement like

    With objWord
    .Visible = True
    .Documents.Add (WordTemplate)
    .ActiveDocument.Bookmarks("GameDate").Select
    .Selection.Text = (CStr(gamedate))
    End With

    Does anyone know the answer to the above issue or can you suggest an
    alternative

    thanks
     
    JP SIngh, Jan 20, 2005
    #1
    1. Advertising

  2. JP SIngh wrote:
    > HI All
    >
    > I just wonder if anyone has created a word document using ASP.
    >
    > I am able to create a work document with ASP without any problem but
    > what I want to do is slightly more than I know. I am sure someone
    > where will know how to do the following.
    >
    > We have a Word Template which is our standard contract type. I have
    > some data stored my access database record. I want to merge the two
    > together. i.e. take the data from access and insert into various
    > points in the word document. The points where I need to insert the
    > data is definded by Bookmarks in Word. This is how you can do it VBA
    > but not sure if this is possible in ASP.
    >
    > In VBA I will write a statement like
    >
    > With objWord
    > .Visible = True
    > .Documents.Add (WordTemplate)
    > .ActiveDocument.Bookmarks("GameDate").Select
    > .Selection.Text = (CStr(gamedate))
    > End With
    >
    > Does anyone know the answer to the above issue or can you suggest an
    > alternative
    >

    If it was a desktop app, I would not hesitate to suggest using Word
    Automation for this. But seeing that you want to do it in a server app, I'm
    much more hesitant. See:
    http://support.microsoft.com/default.aspx?scid=KB;en-us;q257757

    I would rather create an html version of the Word template and use simple
    string Replace to insert the data. You can use contentType to control what's
    sent to the client.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Jan 20, 2005
    #2
    1. Advertising

  3. JP SIngh

    Guest Guest

    As per Bobs suggestion, use contentType as per this
    technique:

    http://www.devx.com/asp/Article/17964

    First, get the data you need from Access and put each item
    into a Session variable or an Array and store the array in
    a session variable.

    Then create your document as you want it to look in Word
    with all its formatting ect. However whereever you want
    to insert data from your Access database type something
    like this (for full name):

    VAR_PERSON_FULL_NAME

    Then save your template as an RTF file type. Open the RTF
    file you just created in Notepad. What you will see is a
    load of RFT coding. However buried in this mess will be
    your codes, ie VAR_PERSON_FULL_NAME. Copy everything from
    the RTF file (without changing everything) into a clean
    (blank) ASP page. Press home on your keyb to get right to
    the start of the page and paste this:

    <%Response.ContentType = "application/msword"%>

    Do not add any spaces or other formatting after the
    ContentType declaration above. You want to end up with
    this:

    <%Response.ContentType = "application/msword"%>{\rtf1\...

    Now, do a search and find your VAR_PERSON_FULL_NAME code,
    replace it with <%=Session("full_name")%>. Repeat for all
    other codes. Run your ASP and you should generate your
    Word document in the browser. Save and select Word as the
    filetype and your done!

    HTH,

    Colin

    >-----Original Message-----
    >HI All
    >
    >I just wonder if anyone has created a word document using

    ASP.
    >
    >I am able to create a work document with ASP without any

    problem but what I
    >want to do is slightly more than I know. I am sure

    someone where will know
    >how to do the following.
    >
    >We have a Word Template which is our standard contract

    type. I have some
    >data stored my access database record. I want to merge

    the two together.
    >i.e. take the data from access and insert into various

    points in the word
    >document. The points where I need to insert the data is

    definded by
    >Bookmarks in Word. This is how you can do it VBA but not

    sure if this is
    >possible in ASP.
    >
    >In VBA I will write a statement like
    >
    > With objWord
    > .Visible = True
    > .Documents.Add (WordTemplate)
    > .ActiveDocument.Bookmarks("GameDate").Select
    > .Selection.Text = (CStr(gamedate))
    >End With
    >
    >Does anyone know the answer to the above issue or can you

    suggest an
    >alternative
    >
    >thanks
    >
    >
    >.
    >
     
    Guest, Jan 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,391
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    593
    SpamProof
    Oct 21, 2003
  3. Stelios Skiathitis
    Replies:
    1
    Views:
    2,054
    Ken Cox [Microsoft MVP]
    May 25, 2005
  4. apondu
    Replies:
    0
    Views:
    603
    apondu
    Jul 19, 2007
  5. Michael G. Schneider

    Modifying a Word document without using Word Automation

    Michael G. Schneider, Dec 15, 2003, in forum: ASP General
    Replies:
    5
    Views:
    289
    el.c. - myLittleTools.net
    Dec 16, 2003
Loading...

Share This Page