views:

288

answers:

2

I am using VSTO to fill data into a table in a Microsoft Word 2007 template. The amount of data varies and filling many pages (+50) takes a lot of time.

The code I use to create a table:

Word.Table table = doc.Tables.Add(tablePosition, 
                                  numberOfRows, 
                                  8, 
                                  ref System.Reflection.Missing.Value, 
                                  ref System.Reflection.Missing.Value);

I suspect that the time consumption is due to the communication between Visual Studio (C#) and Word each time I insert data into a cell. If this is the case, it might be faster to create the table in C# and afterwards insert it into Word.

The Microsot.Office.Interop.Word.Table is an abstract class - thus I cannot do this

Word.Table table = new Word.Table();

which would have been handy.

Are there other possibilities when just using VSTO?

Regards, Casper

A: 

Allthough I do similar things with LabVIEW7.1 and Word2000, the problem is similar. I have not found a way to insert blocks of data (table) with one command. There is even a problem when inserting single elements too fast for word, it occasionally hangs than and must be killed in order to solve that. Unfortunately there is no event nor property that signals word's ability to accept the next command and data set - at least I could not find anything. As this is in a test sequencer I have the time to feed the test results into word with delays long enough to assume word is ready again when the next portion of data is send...

Greetings from Germany!

Uwe

LuI
@Lul: Thanks for your thoughts on the subject. :)
Chau
+1  A: 
  • Try creating the table in HTML Clipboard format, add to clipboard, then paste.
  • Try creating the table in HTML and inserting it.
  • Try creating tab-delimited string with newline character for each record. Insert string with selection, convert selection to table using tabs as delimiter.
  • Create template as XML, transforming data with Xslt into Word XML Document.
  • Create template as a "Directory Mail Merge", perform mail merge with data.

Depending on your requirements, I recommend using the mail merge technique because the user can edit the template and mail merges are fast, especially if you have 50+ pages.

AMissico
@Amissico: Thanks for your suggestions. I will try them as soon as I can =)
Chau