Free Support Forum - aspose.com

Table within a table using aspose?

Hi,

i do have a case where a table is being merged with some data, it will be multiple rows.
i do have another table below that which also merges some data. My case is that, the 1st row in the first table is related to the second table.
So i should get the first row of the first table followed by some rows associated with the second table and then second row of first table followed by associated rows of second table. and soon.
How is it possible?
In the case you did not understand my question, i am attaching a word template.It is better if you see the attachment.
Please do tell me how to do that?

Thanks,
raviteja

Hi

Thanks for your inquiry. I think that a solution for you is building up a resulting document from several documents. You should use two templates. See the following code. Templates are attached.

public void TestMailMerge_105146()

{

DataTable list = new DataTable("list");

list.Columns.Add("LineNbr");

list.Columns.Add("TermStart");

list.Columns.Add("TermEnd");

list.Columns.Add("NbrVisits");

list.Columns.Add("Product");

list.Columns.Add("Nbrs");

list.Columns.Add("Price");

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

{

DataRow row = list.NewRow();

row["LineNbr"] = i.ToString();

row["TermStart"] = DateTime.Now.ToString();

row["TermEnd"] = DateTime.Now.ToString();

row["NbrVisits"] = "10";

row["Product"] = "test";

row["Nbrs"] = "10";

row["Price"] = "100";

list.Rows.Add(row);

}

//open template

Document doc = new Document(@"400_105146_raviteja\in1.doc");

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField_105146);

doc.MailMerge.ExecuteWithRegions(list);

//save document

doc.Save(@"400_105146_raviteja\out.doc");

}

void MailMerge_MergeField_105146(object sender, MergeFieldEventArgs e)

{

if (e.FieldName == "list1")

{

DocumentBuilder builder = new DocumentBuilder(e.Document);

builder.MoveToMergeField("list1");

DataTable list1 = new DataTable("list1");

list1.Columns.Add("LineQty");

list1.Columns.Add("LineType");

list1.Columns.Add("LineSN");

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

{

DataRow row = list1.NewRow();

row["LineQty"] = i.ToString();

row["LineType"] = "abc";

row["LineSN"] = i.ToString();

list1.Rows.Add(row);

}

Document doc2 = new Document(@"400_105146_raviteja\in2.doc");

doc2.MailMerge.ExecuteWithRegions(list1);

InsertDocument(builder.CurrentParagraph, doc2);

}

}

I hope that this information will help you. Please let me know if you would like to know something else.

Best regards.

Hi,

where is the method for Insert Document. Can you pleae give me that one

Hi,

Got the Insert Document, Dont worry about that.Thank you. Thats working.

Hi,
when i am inserting data from the database the merge fields in the second document are not merging properly. i mean for the first row of first document, the second document rows are merignf fine, when coming to the second row, the second doucment mergefileds, i got twice the data,
In the documnet attached, the data in teh second document , there are only two rows, but for the second row, u can see 4 rows.

Please let me know how to solve it.

Thanks,
Ravi

Hi

Are you sure that there are only 2 rows? Could you please provide me data that you use to perform mail merge (you can store data to XML file and attach it here). I will investigate this and provide you more information soon.

Best regards.

In database there are only two rows. but i think something wrong is there with teh code, i am attaching the code. Even the xml genereated is also coming with 4 rows. So please do let me know, if there is somwthing wrong with the code.I think the datatable for teh second document is filling twice, how to solve it.

Sorry once again, I got it. Thank you very much for every thing.

I modified your code. I think that this will solve your problem.

Best regards.