When the loop table rows, how to merge cells?
I use the following method to Merge table data
DataTable myRegionTable = new DataTable();
doc.MailMerge.ExecuteWithRegions(myRegionTable);
thanks!
When the loop table rows, how to merge cells?
I use the following method to Merge table data
DataTable myRegionTable = new DataTable();
doc.MailMerge.ExecuteWithRegions(myRegionTable);
thanks!
Hi Kin,
Thanks for your inquiry.
Do you mean merging the cells of a table whose rows are dynamically generated by regions during mail merge? If so you may want to look into this code here which provides an example of how to merge cells of a table in this situation.
Even if it’s not exactly what you are looking for, the code may still be helpful.
Thanks,
Please give me the code!
thanks!
Hi Kin,
My apologises, I have fixed the link. Please follow that link and you will find the code and details attached to that post.
Thanks,
I’m sorry, I do not understand how to achieve, you can give me the specific code? pls check word.doc!
thanks!
Hi Kin,
Thanks for this additional information.
My apologises, I misunderstood what you were looking for. Please try using this code instead below to merge the cells in your table like in your example. The MergeCells method can be found here.
Document doc = new Document("word.doc");
Table firstTable = (Table) doc.GetChild(NodeType.Table, 0, true);
// Note that each index is 0 based. E.g Cells[1] is the second cell in the row.
MergeCells(firstTable.Rows[1].Cells[1], firstTable.Rows[1].LastCell);
MergeCells(firstTable.Rows[2].FirstCell, firstTable.Rows[2].LastCell);
Thanks,
hi
Thank you for your help!pls check test.doc!I have other problems!
thanks!
Hi Kin,
Thanks for your inquiry.
Sure, you can set up nested mail merge to achieve this. Please see this article here for a demonstration on how this is done
I have also attached your datasource which is modified to show how to the “Note” table should be included.
Thanks,
hi
sorry, I do not understand the example you gave! program how to use the xsd file? you can give me the specific code? pls check 1.doc
thanks!
Hello
Thanks for your request. I created simple example for you. Sample template and output document are attached. Here is the code:
// Open template.
Document doc = new Document("in.doc");
// Execute mail merge with regions.
doc.MailMerge.ExecuteWithRegions(GetData());
// Save output document.
doc.Save("out.doc");
///
/// Returns dummy datasource, which contaion two tables with parent-child relationships.
/// The first table name is "ParentRegion", the child table name is "ChildRegion".
///
private static DataSet GetData()
{
DataSet ds = new DataSet();
// Create two tables and add them into the data set.
DataTable parent = new DataTable("ParentRegion");
parent.Columns.Add("id");
parent.Columns.Add("ParentName");
DataTable child = new DataTable("ChildRegion");
child.Columns.Add("parnetId"); // this column is needed to create relationshoip between tables.
child.Columns.Add("ChildName");
child.Columns.Add("ChildDescription");
// Add tables into the data set and add relationship.
ds.Tables.Add(parent);
ds.Tables.Add(child);
ds.Relations.Add(parent.Columns["id"], child.Columns["parnetId"]);
// Structure of our datasource is ready. Let's add some dummy data.
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
parent.Rows.Add(new object[]
{
i,
string.Format("Parent Name #{0}", i)
});
for (int j = 0; j < rnd.Next(1, 15); j++)
{
child.Rows.Add(new object[]
{
i,
string.Format("child {0} {1}", i, j),
string.Format("description of child {0} {1}", i, j)
});
}
}
return ds;
}
Hope this helps. Also, please see the following link to learn more about this feature:
https://docs.aspose.com/words/net/nested-mail-merge-with-regions/
Best regards,
hi
I already know before you give the code, I now need to implement more complex example of! pls check test.doc and test.xml ,Can you help me generate pdf realize it?
thanks!
Hi Kin,
Thanks for your inquiry. Actually, the example, provided in the article suggested by Adam and later by Andrey, shows the technique you have to use to fill templates like yours.
Just follow instructions provided in the article. Your template actually looks mostly the same as the template form the article. So it should not be difficult to fill it with data just following the instruction.
Best regards,
hi
DataSet have 4 table, I have the following relationship, the generated pdf is a problem, I found that table “contentplanS” and table “Orders” is not associated, how do I do? pls check ds.xml
doc = new Document("C:\\pps1.doc");
DataSet ds = new DataSet();
ds.ReadXml("C:\\ds.xml");
ds.Relations.Add(ds.Tables["contentplanS"].Columns["id"], ds.Tables["Orders"].Columns["parnetId"]);
ds.Relations.Add(ds.Tables["Orders"].Columns["id"], ds.Tables["riderS"].Columns["parnetId"]);
ds.Relations.Add(ds.Tables["riderS"].Columns["id"], ds.Tables["ItemS"].Columns["parnetId"]);
ds.Relations.Add(ds.Tables["riderS"].Columns["id"], ds.Tables["Notes"].Columns["parnetId"]);
doc.MailMerge.ExecuteWithRegions(ds);
doc.SaveToPdf("C:\\xx.pdf");
Hi Kin,
Thanks for your inquiry. It is not quite clear what you mean. As I can see, you added a relationship between Orders and contentplanS tables in your code. So everything should work as expected.
I would suggest you to simplify your template and try to execute mail merge. If you get the expected result in output, you can try adding more complexity in your template. Using such technique, you will be able to isolate where the problem occurs.
Best regards,
hi
As I understand,My code and ds.xml should generate the results pdf.doc,But now generation is xx.pdf,I want to generate pdf.doc, me how to modify the code and ds.xml? I uploaded my template!pls check!
thanks!
Hello
Thanks for your request. In this case you should just change the one line of code:
// Save as DOC
doc.Save("C:\\Temp\\pdf.doc", SaveFormat.Doc);
Best regards,