Word App Scope - fill table with data

Hi,

I need some advice on a topic that drives me crazy right now.

I want to generate a word document where I take a template file and populate it with data.
For the most part it is quite easy as I just set bookmark content activity and all is fine…except when I reach a table where I want to put data in. I have multiple data rows that should be entered into that table but the number of data rows is dynamically.

The most straight forward way was to create a datatable with all data I want to put in the document and paste it in via set bookmark content but the problem is that I loose my table formatting in the word document.

And on top: The table should scale dynamically. So I have one reference row and depending on how many items I have i need to update the number of rows in that table.

Any tips on how I could solve my issue?

Thank you.

Hi @SenorChang

The usual workaround is to keep one formatted “template” row in the Word table. Then, use Word activities (like Find/Replace or Insert Row via Word Application Scope) to duplicate that row for each item in your data. After inserting the required number of rows, you populate each cell individually. This way the formatting is preserved and the table grows dynamically.

Avoid pasting a whole datatable into a bookmark if formatting matters, because Word will rebuild the table and drop your styles. The row-by-row approach is slower but it’s the most reliable way to keep formatting and handle dynamic row counts.

@SenorChang

Better insert the table using Activities - Insert DataTable in Document

then use vba or .net code to format the table as you need

cheers

Hi,

This was exactly my original approach to add new data row to the table but the word package does not have an activity to add a data row for word itself. I am using modern word app scope.

Do you have a small example workflow to share?

Keep one formatted “template” row in your Word table. In a loop, duplicate that row for each data item (via copy-paste or VBA) and fill each cell individually. Avoid pasting the whole datatable at once, as it breaks formatting. This way, the table grows dynamically while preserving styles.

Hey,

I already tried invoke code to duplicate the row in the table but it failed. I am not sure if this is because I use the invoke code within Word Application Scope.

Hi @SenorChang

Keep one formatted template row, use Invoke VBA inside Word Application Scope to duplicate it for each data item, then fill each row’s cells individually. Avoid pasting the whole datatable to preserve formatting.