Hello,
I’m working on a report generation in which i populate (with mail merge) a table.
Here is a simplified version of the table :
-------------
Header row
-------------
Category 1
---------
Item 1
---------
Item 2
-------------
Category 2
---------
Item 1
---------
Item 2
I need to repeat the header row when the table spans more than one page but i want to repeat the current category row too.
With my code, i’m already able to add the category row (group by) and the header row is configured in the word template to repeat when the table spans more than one page.
Here is my code :
DataTable data = MockObject.GetCompetencesDataTable();
Document doc = new Document(System.IO.Path.Combine(DocPath, "template3.doc"));
DocumentBuilder builder = new DocumentBuilder(doc);
doc.MailMerge.MergeField += new MergeFieldEventHandler(HandleMergeField);
doc.MailMerge.ExecuteWithRegions(data);
return doc;
}
private void HandleMergeField(object sender, MergeFieldEventArgs e)
{
DocumentBuilder builder = new DocumentBuilder(e.Document);
if (e.TableName.Equals("Competences"))
{
if (e.DocumentFieldName.Equals("Activite"))
{
builder.MoveToMergeField(e.FieldName);
// Get table
Table myTable = (Table) builder.CurrentNode.GetAncestor(NodeType.Table);
Row headerRow = myTable.Rows[3];
Row currentRow = (Row) builder.CurrentNode.GetAncestor(NodeType.Row);
if (!activites.Contains((string) e.FieldValue))
{
Row header = null;
if (activites.Count == 0)
{
header = headerRow;
}
else
{
header = (Row) headerRow.Clone(true);
}
header.FirstCell.FirstParagraph.RemoveAllChildren();
myTable.InsertBefore(header, currentRow);
builder.MoveTo(header.FirstCell.FirstParagraph);
builder.CurrentParagraph.ParagraphFormat.KeepWithNext = true;
builder.Write((string) e.FieldValue);
activites.Add((string) e.FieldValue);
}
}
}
}
But i don’t find a way to repeat the current category row when the table spans more than one page.
I checked the forum and i already know that Aspose doesn’t have a “current page” or a “page position” support but have you a solution ? (other than split the table…)
P.S : the attachment is the report generated