Free Support Forum - aspose.com

NEXT in Regions

Hi Roman,

I’ve got a multi row DataTable that I need to show in a three column word table.
The presented layout might look like this:

Row1Value Row2Value Row3Value
Row4Value Row5Value

I tried to use NEXT merge field to force moving to the next record but that didn’t seem
to produce desired effect. I ended up with this layout

Row1Value Row1Value Row1Value
Row2Value Row2Value Row2Value


Should NEXT field be honored here? Or what are my options?

Thanks!
Abdim

Hi Abdim,

This is an interesting approach and it should work because regions and no regions mail merge is performed by the same piece of code. I will look at this one.

Hi Abdim,

I’ve added a unit test for this scenario. It actually works fine. Just check your document to make sure you do have the NEXT fields.

Here is my code:

///


/// Abdim reported that NEXT in mail merge regions was not working. But it actually works.
///

[Test]
public void TestMailMergeRegionWithNext()
{
TestUtil.SetUnlimitedLicense();
Document doc = TestUtil.Open(“TestMailMergeRegionWithNext.doc”);

DataTable table = new DataTable(“Test”);
table.Columns.Add(“MyValue”);
table.Rows.Add(new object[] {“Value 1”});
table.Rows.Add(new object[] {“Value 2”});
table.Rows.Add(new object[] {“Value 3”});
table.Rows.Add(new object[] {“Value 4”});

doc.MailMerge.ExecuteWithRegions(table);
doc.MailMerge.DeleteFields();

doc = TestUtil.SaveOpen(doc, “TestMailMergeRegionWithNext Out.doc”);

Assertion.AssertEquals(2, doc.Model.GetCountOf(typeof(MdlTableRow)));
Assertion.AssertEquals(
“Value 1\x0007Value 2\x0007Value 3\x0007\x0007” +
“Value 4\x0007\x0007\x0007\x0007\x000c”,
doc.Model.GetText());
}


My document has a table with one row and three cells.

First cell content:
?TableStart:Test??MyValue?

Second cell
NEXT?MyValue?

Third cell
NEXT?MyValue??TableEnd:Test?




Hi Roman,

I have tested this again in my template and it doesn’t work … however, I created
a new template and copied the table alone from the first template and that works!

This may be related to the multiple merges that I am performing on the document.

For each table in dataset
invoke Execute
or ExecuteWithRegions

I think that NEXT should be considered in the scope of the region. What do you think?
Pragmatic?

Regards,
Abdim

NEXT inside a region works properly. Email your original template to word@aspose.com and I will see what the problem was.