add rows to a word table from a dataview or datatable

L

LBowman

I have a dataview with a varying number of records in it. I want to create a
Word table and add the data in my dataview to the table.

Currently, I have created the word table and loop through each record in the
dataview and do the following for each:
wdMMTable.Rows.Add()
iwdRow = iwdRow + 1

wdMMTable.Cell(iwdRow, 1).Range.InsertAfter(dvMailMerge.Item(iRow).Item(0))
wdMMTable.Cell(iwdRow, 2).Range.InsertAfter(dvMailMerge.Item(iRow).Item(1))
wdMMTable.Cell(iwdRow, 3).Range.InsertAfter(dvMailMerge.Item(iRow).Item(2))
(I actually have 18 columns, not just 3)

This is extremely slow for a large number of records and above a certain
number either locks up or crashes the machine.

I have read that the fastest way is to write the data to a string and then
create the table from the string. Is there another, more direct way to add
the records from a dataview to a word table. I am using VB.NET 2003 and MS
Word 2000.

Thank you,
Laure Bowman
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TEJvd21hbg==?=,
I have a dataview with a varying number of records in it. I want to create a
Word table and add the data in my dataview to the table.

Currently, I have created the word table and loop through each record in the
dataview and do the following for each:
wdMMTable.Rows.Add()
iwdRow = iwdRow + 1

wdMMTable.Cell(iwdRow, 1).Range.InsertAfter(dvMailMerge.Item(iRow).Item(0))
wdMMTable.Cell(iwdRow, 2).Range.InsertAfter(dvMailMerge.Item(iRow).Item(1))
wdMMTable.Cell(iwdRow, 3).Range.InsertAfter(dvMailMerge.Item(iRow).Item(2))
(I actually have 18 columns, not just 3)

This is extremely slow for a large number of records and above a certain
number either locks up or crashes the machine.

I have read that the fastest way is to write the data to a string and then
create the table from the string. Is there another, more direct way to add
the records from a dataview to a word table. I am using VB.NET 2003 and MS
Word 2000.
Not that I know of, although VSTO 2005 might have introduced something. But for
that you'd also need Word 2003. So, no. The fastest way would certainly be to
concatenate a string, drop that into a Word range, then convert the Word range
to a table and format.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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

Top