cancel
Showing results for 
Search instead for 
Did you mean: 

To Write A Collection Onto a Word Dynamically

PrateekMehan
Level 6
HI All, I want to write a collection with unknown number of fields into a table in the word document. I know how to do it if the number of fields in the collection are known but if the fields in the collection can vary at run time and I am stuck as how to proceed further. Any suggestions would be appreciated. Thanks.
6 REPLIES 6

Denis__Dennehy
Level 15
Looking at the MS Word VBO object I can see that it has an 'Add Table Row' action. Can you not simply loop through your collection and use this 'Add Table Row' action when required to add additionally required rows?

PrateekMehan
Level 6
I agree with you Dennis but adding a table row would require me to know the number of columns in a collection which I stated could change. That's where I am stuck at , if collection has 2 columns and sometimes 3 columns, how to tackle that??

Denis__Dennehy
Level 15
If you are asking how do i discover the number of rows are in a collection, there is a Count Rows action in the internal collections object, or if you are looping through a collection you simply need to increment a data item counter as you loop?

FirstName
Level 3
Denis I think the question was more around the number of columns, if this isn't fixed and can change from 2 to 3 or more... I'm keen to find a solution to this also as it's something I'm currently being faced with... Thanks

Denis__Dennehy
Level 15
I see... well if the action does not exist in the word interface, your option is probably to create a new action that does what you want. So, I see that the Add Row action has code that looks like: Dim doc as Object = GetDocument(handle,documentname) doc.Tables.Item(TableNumber).Rows.Add() I would suggest that a new Add Column action would be extreamly similar and probably look something like this: Dim doc as Object = GetDocument(handle,documentname) doc.Tables.Item(TableNumber).Columns.Add() NOTE: I don't know if that is the code you need, that is my non-research guess. I would suggest using google to find out for sure. This kind of thing: https://msdn.microsoft.com/en-us/library/office/ff837258.aspx However, I would guess that adding columns is more likely to impact the general formatting of a word document (such as going over the right of page boundary) - so even more actions/logic would probably be required to somehoe counter that.

PrateekMehan
Level 6
Thanks Denis , I would give it a try