Hi Adam,
Thanks for you’re prompt reply. I believe the issue may not be with the tables themselves, but the way I’m removing the paragraphs from the tables.
In the document template, the structure is as follows
TableStart:ClaimTypes
TableStart:Claims TableStart:Messages TableEnd:Messages TableEnd:Claims
TableEnd: ClaimTypes
So, for each claim type, there is a list of claims, and each claim can have a list of messages. Now, when there are messages, they are linked correctly tot the Claims Table, however, for each claim record in the datatable, a new table is created in the document. I believe this is because the table start/end of claims is not contained in the same row in the table (which just isn’t possible as the messages must be after the claim row)
So to get around this in the document, I removed each of the paragraphs around each of the tables, which appeared to join all the tables to be one big ClaimTypes table, which is visible in the document supplied.
After review of the xml of the document, it hasn’t actaully merged the tables at all (even though word interpretes it that way when viewing the document) so when it’s saved to pdf, it renders the tables as it sees them. I wouldn’t care if it left the spaces there between each of the tables, but if you review the documents side by side, you’ll see that some of the claim types from the first table actually span through and under the 2nd table, which is clearly not right.
I believe the way I need to format my data is causing this issue, e.g the table layout, however, I cannot se that this can be resolved. What I need to try and do I believe is merge the tables together where I’m currently just removing the paragraphs.
Any help you can give would be much appreciated. Following is my code used to join the tables and remove the paragraphs.
ClaimTypeTable = DataSourceDataSet.Tables[1];
ClaimsTable = DataSourceDataSet.Tables[2];
Messages = DataSourceDataSet.Tables[3];
DataRelation claimTypeRelation;
DataColumn[] master1 = new DataColumn[]
{
ClaimTypeTable.Columns["ClaimTypeID"]
};
DataColumn[] slave1 = new DataColumn[]
{
ClaimsTable.Columns["ClaimTypeID"]
};
claimTypeRelation = new DataRelation("claimTypeRelation", master1, slave1);
DataSourceDataSet.Relations.Add(claimTypeRelation);
DataRelation messageRelation;
DataColumn[] master2 = new DataColumn[]
{
ClaimsTable.Columns["ClaimNo"], ClaimsTable.Columns["ClaimLineNo"]
};
DataColumn[] slave2 = new DataColumn[]
{
Messages.Columns["ClaimNo"], Messages.Columns["ClaimLineNo"]
};
messageRelation = new DataRelation("messageRelation", master2, slave2);
DataSourceDataSet.Relations.Add(messageRelation);
_doc.MailMerge.ExecuteWithRegions(_dataSources[0].DataSourceDataSet);
DocumentBuilder builder = new DocumentBuilder(_doc);
foreach(Table table in builder.CurrentStory.Tables)
{
if (table.PreviousSibling.NodeType == NodeType.Paragraph)
table.PreviousSibling.Remove();
if (table.NextSibling.NodeType == NodeType.Paragraph)
table.NextSibling.Remove();
ForceNewPagePerTable(_doc, table);
}
_doc.Save(documentName, SaveFormat.Docx);
_doc.Save(@"D:\Test\temp.pdf", SaveFormat.Pdf);
Thanks for you time and assistance.
Nolan