Creating Tables in Word from asp.net

Discussion in 'ASP .Net' started by m3ckon, Aug 3, 2004.

  1. m3ckon

    m3ckon Guest

    Hi there,

    I can succesfully create a word doc from my asp.net page, but I have 2
    issues I need to resolve in order to use it in my app:

    1) Creating a table: I seem unable to create a table, I'm uing the coe
    below, but I'm unsure as to what the Range parameter should be for
    oWordDoc.Content.Tables.Add ???



    2) ASP.net does not seem to let go of the winword process, hence locking
    my document...how can I resolve this??


    Code Listing:
    Dim oWordApp As Word.Application
    Dim oWordDoc As Word.Document

    Dim oPara1 As Word.Paragraph
    Dim oRng As Word.Range

    Dim oTable1 As Word.Table


    oWordApp = CreateObject("word.application")
    oWordApp.Visible = True

    oWordDoc = oWordApp.Documents.Add

    oPara1 = oWordDoc.Content.Paragraphs.Add
    oPara1.Style = "Heading 1"
    oPara1.Range.Text = "Text on the page"
    oPara1.Range.InsertParagraphAfter()

    Dim r, c As Integer
    oTable1 = oWordDoc.Content.Tables.Add(???range??help???, 2, 3)

    For r = 1 To 2
    For c = 1 To 3
    oTable1.Cell(r, c).Range.Text = "r" & r & "c" & c
    Next
    Next
    oTable1.Range.InsertParagraphAfter()

    oWordDoc.SaveAs("c:\\test3.doc")
    oWordDoc.Quit()


    Regards,

    M3ckon

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    m3ckon, Aug 3, 2004
    #1
    1. Advertising

  2. m3ckon

    Scott M. Guest

    The easiest way to get the code you need to build the Word table is to
    record a macro in Word of you creating a table using the table menu. Then
    you can just copy the code from the macro editor into VS .NET.



    "m3ckon" <> wrote in message
    news:...
    > Hi there,
    >
    > I can succesfully create a word doc from my asp.net page, but I have 2
    > issues I need to resolve in order to use it in my app:
    >
    > 1) Creating a table: I seem unable to create a table, I'm uing the coe
    > below, but I'm unsure as to what the Range parameter should be for
    > oWordDoc.Content.Tables.Add ???
    >
    >
    >
    > 2) ASP.net does not seem to let go of the winword process, hence locking
    > my document...how can I resolve this??
    >
    >
    > Code Listing:
    > Dim oWordApp As Word.Application
    > Dim oWordDoc As Word.Document
    >
    > Dim oPara1 As Word.Paragraph
    > Dim oRng As Word.Range
    >
    > Dim oTable1 As Word.Table
    >
    >
    > oWordApp = CreateObject("word.application")
    > oWordApp.Visible = True
    >
    > oWordDoc = oWordApp.Documents.Add
    >
    > oPara1 = oWordDoc.Content.Paragraphs.Add
    > oPara1.Style = "Heading 1"
    > oPara1.Range.Text = "Text on the page"
    > oPara1.Range.InsertParagraphAfter()
    >
    > Dim r, c As Integer
    > oTable1 = oWordDoc.Content.Tables.Add(???range??help???, 2, 3)
    >
    > For r = 1 To 2
    > For c = 1 To 3
    > oTable1.Cell(r, c).Range.Text = "r" & r & "c" & c
    > Next
    > Next
    > oTable1.Range.InsertParagraphAfter()
    >
    > oWordDoc.SaveAs("c:\\test3.doc")
    > oWordDoc.Quit()
    >
    >
    > Regards,
    >
    > M3ckon
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Scott M., Aug 3, 2004
    #2
    1. Advertising

  3. m3ckon

    m3ckon Guest

    Thanks for the reply

    I've managed to progress and create the tables ok, however, ASP.NET
    seems to not let go of the winword process at all.

    Can someone please tell me how to close this object???

    M3ckon


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    m3ckon, Aug 4, 2004
    #3
  4. m3ckon

    m3ckon Guest

    Found out how to get round this....

    For the close I used the following statement:

    CType(oWordApp, Word._Application).Quit()

    (oWordApp is if Type Word.Application)

    Hope it Helps

    M3ckon


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    m3ckon, Aug 5, 2004
    #4
    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. matthew rutherford via .NET 247

    asp.net and creating word docs on the server

    matthew rutherford via .NET 247, Apr 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    431
    Steve C. Orr [MVP, MCSD]
    Apr 28, 2004
  2. Nikhil Patel

    creating word document in asp.net

    Nikhil Patel, May 12, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    995
    Nikhil Patel
    May 13, 2004
  3. =?Utf-8?B?Tm92aWNl?=

    Creating Word Document in ASP.NET Application

    =?Utf-8?B?Tm92aWNl?=, Aug 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    12,685
    =?Utf-8?B?Tm92aWNl?=
    Aug 17, 2004
  4. nish
    Replies:
    1
    Views:
    12,375
    mthakershi
    Aug 8, 2006
  5. Sharon
    Replies:
    0
    Views:
    596
    Sharon
    Jul 27, 2005
Loading...

Share This Page