We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

The use of repeaters / TableStart and End

I have a question about the use of repeaters in aspose.word. For some reason any text I place before the TableStart is duplicated, and I was wondering if this is a bug or by design. A simple example:

Names: <><> / <>

The result I am expecting is:

Names: Name1 / Name2 / Name3 /

But aspose returns:

Names: Name1 /
Names: Name2 /
Names: Name3 /

Shouldn't only the things between TableStart and TableEnd be repeated and not the things you put in front of TableStart?

If you need I could send you an example of a Word document in which this occurs.


This message was posted using Aspose.Live 2 Forum

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. If you insert TableStart and TableEnd merge fields into the same paragraph, whole paragraph will be repeated for each record in your data source. This is by design. We will consider adding an additional mail merge syntax, which will allow repeating only part of paragraph. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

While you are waiting for this feature, you can try implementing a simple workaround using MergeField event handler. The idea is that you prepare string, which should be insert into merge field in your code. Let’s suppose you have merge field Names in your template (without regions). You need to insert list of names into this field. Here is a simple code, which will allow you to achieve this:

// Create a dummy datasource.

DataTable data = new DataTable();

data.Columns.Add("Name");

// Add some dummy data.

for (int i = 0; i < 10; i++)

data.Rows.Add(new object[] {string.Format("name_{0}", i)});

// Open template.

Document doc = new Document(@"Test001\in.doc");

// Add MergeField event handler.

doc.MailMerge.MergeField += new Aspose.Words.Reporting.MergeFieldEventHandler(MailMerge_MergeField);

// Execute simpel mail merge.

// As a value of th efield we put DataTable.

doc.MailMerge.Execute(new string[] {"Names"}, new object[] {data});

// Save output document.

doc.Save(@"Test001\out.doc");

===============================================================

void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)

{

if(e.FieldName == "Names")

{

// Get DataTable with data and prepare strign, which should be inserted into the mergefield.

DataTable data = (DataTable)e.FieldValue;

string dataText = string.Empty;

foreach (DataRow row in data.Rows)

dataText += string.Format("{0}, ", row["Name"].ToString());

e.Text = dataText;

}

}

Hope this helps.

Best regards.

what if I had more than one field which would be formated differetnly?

i.e. - /

where name would be one font/color and phone number would be another?

would it still be possible to use this approach?

Thanks!

Igor

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Unfortunately, this approach will not work for few fields. So, you need to wait when this feature will be added into Aspose.Words or use the approach suggested by Adam in other your thread:

http://www.aspose.com/community/forums/238852/mailmerge-is-it-possible-to-repeat-data-inside-one-paragraph/showthread.aspx

Best regards.

Hi,
is this feature mentioned already in a AsposeWord version?

Hi Sascha,


Thank you for inquiry. Yes, we have logged it as new feature request as WORDSNET-3197 in our issue tracking system. Our team will look into this requirement and you’ll be notified via this forum thread once it is supported in future.

We’re sorry for the inconvenience.

Hi,


Thanks for being patient.

Regarding WORDSNET-3197, it is to update you that we have closed this issue. We have introduced a new LINQ Reporting Engine which is a part of the Aspose.Words API that enables you to build reports using an extended set of reporting features. The engine enables you to reference business objects of your application in report templates directly, which agrees well with Domain-Driven Design widely used in modern software development. Moreover, the engine uses a subset of C# language in its template syntax. These features enable you as a developer to compose report templates in a familiar and intuitive way.

For example, using this new reporting engine you can repeat part of a Paragraph as follows:

DocumentBuilder builder = new DocumentBuilder();

builder.Write("The items are: <><>, <>and others.");

Document doc = builder.Document;

ReportingEngine engine = new ReportingEngine();

engine.BuildReport(doc, new string[]{ "Item1", "Item2", "Item3" }, "items");

doc.Save(“out.docx”);


For more details, please visit this article:
http://www.aspose.com/docs/display/wordsnet/Working+with+Common+Data+Bands

I hope, this helps.

Best regards,

The issues you have found earlier (filed as WORDSNET-3197) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(8)

A post was split to a new topic: Aspose.Words Mail Merge question