Mergefield spanning MS Word table cells

Is there a way to generate the replacement string for a Mergefield such that it can span multiple cells in an MS Word table? I want to generate a string that has cell breaks in it, for instance “A columnbreak B columnbreak C rowbreak D columnbreak E columnbreak F rowbreak”.

“A” appears in one cell, “B” in the next cell and “C” in the next cell. “A”, “B” and “C” are in the same row, “D”, “E” and “F” are on the following row. Thank you.

Hi Ken,

Thanks for your inquiry.

I think you can use the FieldMergingCallback handler to achieve what you looking for. You can check out some of the examples on the above link which will give you some ideas. You could use it to split the FieldValue of a merged field into separate cells during runtime. You may find it may be easier to simply have multiple fields in separate cells and split the data into these separate fields before calling mail merge.

If you post your template, sample data source and expected output here we will be glad to help you further.

Thanks,

Hi, Adam,

Is there a reason that I cannot use the ControlChars in Aspose.Words Document Processing API | Aspose API References to embed breaks to move from column to column and row to row ? thank you.

P.S. I attached a .jpg of the multi-row type of thing that I want to do. I can’t conveniently break-up the mergefield into multiple ones.






Hi Ken,

Thanks for this additional information.

I believe these characters are used to signify the layout of a table in a flat range. They don't however control how a table is built or allow you to break a span of text into separate cells.

You could, for example, insert these cell markers and then run a snippet of code which takes these and parses them into proper cells and rows. This would be the same as what I suggested using FieldMergingCallBack for, except when using FieldMergingcallback you would create the cells during the merging process instead of using any markers.

I'm afraid I am unable to view the image you attached in your last post. Could you please try attaching it again?

Thanks,

Hi Ken,

I am able to see one of the images now. I have produced a quick template that demostrates using separate fields to fill the table. I have sent the document to your inbox. You can then use MailMerge.ExecuteWithRegions to populate the data from your data source. The table rows will grow for each record in the data source. Please see the documentation on Mail merge with regions here for more information.

Thanks,