Free Support Forum - aspose.com

Confirmation on Feature Before Purchase

Currently we have an .NET web application that write to Word generated XML files containing fields. The major issue with this is the concatenation of multiple templates into a single Word compatible (.doc) file.

Example: Database query generates 20 rows with X number of fields to be passed into 3 different .DOC template files and generate 1 new .DOC file, with appropriate page breaks, headings, footers, etc.

Is this possible with Aspose.Words and with templates and queries already created is there an estimate programming time to see a rough example?

Thanks!

Hi

Thanks for your inquiry. Yes, I think that you can achieve this using Aspose.Words. For example see the following code. Also see attachment.

DataTable table = new DataTable();

table.Columns.Add("Field1");

table.Columns.Add("Field2");

table.Columns.Add("Field3");

DataRow row = table.NewRow();

row[0] = "test1";

row[1] = "test2";

row[2] = "test3";

table.Rows.Add(row);

//open templates

Document doc1 = new Document(@"367_103139_runtoofar\in1.doc");

Document doc2 = new Document(@"367_103139_runtoofar\in2.doc");

Document doc3 = new Document(@"367_103139_runtoofar\in3.doc");

//execute mail merge

doc1.MailMerge.Execute(table);

doc2.MailMerge.Execute(table);

doc3.MailMerge.Execute(table);

//merge documents

foreach (Section sect in doc2.Sections)

{

doc1.Sections.Add(doc1.ImportNode(sect, true, ImportFormatMode.KeepSourceFormatting));

}

foreach (Section sect in doc3.Sections)

{

doc1.Sections.Add(doc1.ImportNode(sect, true, ImportFormatMode.KeepSourceFormatting));

}

//save document

doc1.Save(@"367_103139_runtoofar\out.doc");

I hope that this will help you.

Please let me know if you would like to know something else.

Best regards.