By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,555 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,555 IT Pros & Developers. It's quick & easy.

Creating Tables in Word from asp.net

P: n/a
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!
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
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" <an*******@devdex.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
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!

Nov 18 '05 #2

P: n/a

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!
Nov 18 '05 #3

P: n/a

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!
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.