Hi!
What I want to achieve is to MailMerge a datasource into one single table via Doc API. I have already succeeded in creating a table, add a merge field to each cell and do a MailMerge, but this results in a single table row per record each with two paragraphs between them. Here is my code:
Regards
Neils
What I want to achieve is to MailMerge a datasource into one single table via Doc API. I have already succeeded in creating a table, add a merge field to each cell and do a MailMerge, but this results in a single table row per record each with two paragraphs between them. Here is my code:
Table table =
new
Table();
TableRow row1 =
new
TableRow();
TableCell cell1 =
new
TableCell();
Paragraph p1 =
new
Paragraph();
FieldRangeStart start =
new
FieldRangeStart();
FieldRangeEnd end =
new
FieldRangeEnd();
end.Start = start;
start.Field =
new
MergeField() { PropertyPath =
"FirstName"
};
Span s1 =
new
Span();
s1.Text =
"{MERGEFIELD FirstName}"
;
p1.Inlines.Add(start);
p1.Inlines.Add(s1);
p1.Inlines.Add(end);
cell1.Blocks.Add(p1);
row1.Cells.Add(cell1);
... (add more table cells)
table.Rows.Add(row1);
section.Blocks.Add(table);
doc2.Sections.Add(section);
doc2.MailMergeDataSource.ItemsSource = ExamplesDataContext.Employees;
doc2.ChangeAllFieldsDisplayMode(FieldDisplayMode.Result);
doc.GoToBookmark(
"tm1"
);
doc.InsertFragment(
new
DocumentFragment(doc2.MailMerge(
false
)));
Regards
Neils