Hi
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your request. Sure you can achieve this using Aspose.Words. You should just specify mail merge data source. Please see the following link for more information:
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.document.mailmergesettings.html
For example, see the following code:
string dataSource = @"C:\Temp\test.tmp";
Document doc = new Document();
doc.MailMergeSettings.DataType = MailMergeDataType.TextFile;
doc.MailMergeSettings.MainDocumentType = MailMergeMainDocumentType.FormLetters;
doc.MailMergeSettings.DataSource = dataSource;
doc.MailMergeSettings.Query = string.Format(@"SELECT * FROM {0}", dataSource);
Regex whiteSpaceRegex = new Regex(@"\s+");
using (StreamReader reader = new StreamReader(dataSource, Encoding.UTF8))
{
string firstLine = reader.ReadLine();
string[] fieldNames = firstLine.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < fieldNames.Length; i++)
{
OdsoFieldMapData mapData = new OdsoFieldMapData();
mapData = new OdsoFieldMapData();
mapData.Column = i;
mapData.MappedName = fieldNames[i];
mapData.Name = whiteSpaceRegex.Replace(fieldNames[i], "_");
mapData.Type = OdsoFieldMappingType.Column;
doc.MailMergeSettings.Odso.FieldMapDatas.Add(mapData);
}
}
doc.Save(@"Test001\out.doc");
Datasouce is txt file, which contains data in the following format:
Field1,Field2,Field3,Field4,
, , , ,
Also, if you would like to create template from scratch, you should insert mergefields into your document. You can achieve this using DocumentBuilder. Please see the following link for more information.
http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.documentbuilder.insertfield_overload_1.html
Hope this helps.
Best regards.