Creating Tables in Word from asp.net

M

m3ckon

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
 
S

Scott M.

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.
 
M

m3ckon

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
 
M

m3ckon

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top