473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating Tables in Word from asp.net

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
3 4206
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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
6
by: campwes | last post by:
Hey, all. I'm trying to develop a C# app that creates Word 2003 mail merge documents with an Oracle 9i database as the datasource. I used the following as an example of how I can start out: ...
5
by: serge | last post by:
What is the best way to run one command and have a database be created and sql scripts run on it to create the tables, indexes, triggers, procedures, etc.? Is there an existing tool free or...
3
by: Phil Rutter | last post by:
Hello All, I have about 700 word documents that have 2 tables one is static 4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100 what i wolud like to do is open the word doc....
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
0
by: nish | last post by:
Hi, I am struggling with this code. I am trying to create 3 separate tables and print them in word, however I end up with 1 big table and 1 nested table inside and 1 more nested table within...
2
by: elziko | last post by:
I'm trying to create a new table in word from a DataTable (sourceTable): objDoc.tables.Add(Range:=objDoc.Range, NumRows:=sourceTable.Rows.Count, NumColumns:=sourceTable.Columns.Count,...
5
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the...
4
by: RSH | last post by:
Hi, I have a situation where I have created a little application that makes an Access database from a SQL Database for reporting purposes. it does the job well, but it seems a bit slow. Is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.