We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail merged report implementing a �group by� having multiple tables on one page

We are trying to create a mail merged report implementing a “group by” clause which is almost identical to what you have done in the Aspose demo/sample code: Product Catalogue Demo were you display products per category .

Ours, however, has one important difference. We need to repeat several tables (2 or 3) for every page in the word document. In the Product Catalogue Demo, a new page is created for every category. Is there a way to have multiple categories on each page?

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try setting “Section Start” of the first section in your template to “Continuous”. (Place cursor at the beginning of the document, select “Page Setup”, go “Layout” tab and specify “Section Start”).

Hope this helps.

Best regards.

Alexey,

Thanks for your QUICK responses!

We tried to implement the setting you suggested above, however, when inserting a new section from the source document into the destination document, the tables continued to be adding new pages for each new table into the destinationation document.

Can you give us a code example to see if we are implementing something incorrectly?

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please attach your templates and code for testing? I will investigate the issue and provide you a solution.

Best regards.

private void Test()

{

Document templateDestination = new Document("TestDocument.doc");

var builderOriginal = new DocumentBuilder(templateDestination);

builderOriginal.MoveToBookmark("YourBookmark");

Document tempDoc = new Document();

var builder = new DocumentBuilder(tempDoc);

builder.InsertParagraph();

builder.InsertField(string.Format("MERGEFIELD CategoryName"), "CategoryName");

builder.InsertCell();

builder.Write("Description");

int year = 2009;

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

{

builderOriginal.InsertCell();

builderOriginal.Write(year.ToString());

year--;

}

builder.EndRow();

builder.InsertCell();

builder.InsertField(@"MERGEFIELD TableStart:products", "TableStart:products");

builder.InsertField(@"MERGEFIELD Description", "Description");

year = 2009;

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

{

builder.InsertCell();

builder.InsertField(string.Format("MERGEFIELD {0}", year), year.ToString());

year--;

}

builder.InsertField(@"MERGEFIELD TableEnd:products", "TableEnd:products");

builder.EndRow();

builder.EndTable();

string[] categories = {"Beverage", "soda", "coke"};

foreach (var category in categories)

{

Document compDoc = tempDoc.Clone();

compDoc.MailMerge.Execute(new[] { "CategoryName" },new object[] { category});

DataTable financialComps = GetTestDataTable();

compDoc.MailMerge.ExecuteWithRegions(financialComps);

AppendDoc(_doc, compDoc);

}

}

private DataTable GetTestDataTable()

{

string[] rowDescriptions= {"Sales", "Cost of Goods Sold", "Gross Profit", "Operating Expense", "Operating Income"};

int year = 2009;

DataTable products = new DataTable("products");

products.Columns.Add(new DataColumn("Description", typeof(string)));

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

{

products.Columns.Add(new DataColumn(year.ToString(), typeof(double)));

year--;

}

for (int rowIndex = 0; rowIndex < 4; rowIndex++)

{

DataRow row = products.NewRow();

row[0] = rowDescriptions[rowIndex];

for (int i = 1; i < 3; i++)

{

row[1] = rowIndex;

row[2] = rowIndex + 10;

row[3] = rowIndex + 20;

}

products.Rows.Add(row);

}

return products;

}

private void AppendDoc(Document dstDoc, Document srcDoc)

{

for (int i = 0; i < srcDoc.Sections.Count; i++)

{

//First need to import the section into the destination document,

//this translates any document specific lists or styles.

Section section = (Section)dstDoc.ImportNode(srcDoc.Sections[i], true);

dstDoc.Sections.Add(section);

}

}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. This occurs because you build the second template on fly. Just add highlighted line to your code:

Document tempDoc = new Document();

DocumentBuilder builder = new DocumentBuilder(tempDoc);

builder.CurrentSection.PageSetup.SectionStart = SectionStart.Continuous;

Also, there is no need to use your own AppendDoc method. You can use the following code:

_doc.AppendDocument(compDoc, ImportFormatMode.KeepSourceFormatting);

Hope this helps.

Best regards.

That works fine.

Thanks you

destinationDoc.AppendDocument(source, ImportFormatMode.KeepSourceFormatting);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Above code always adds the sections from the source document, at the end of destination document. Is there a way to add content of the source document to the destination document at a book mark specified in destination document.

Thanks

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Please see the following forum thread to learn how to insert document at bookmark:

Hope this helps.

Best regards.