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

Free Support Forum - aspose.com

Linking DataSource to word document mail merge

Is it possible to do mail merge like ms word using Datasource. Once I have linked to the specific DB. Whenever I open the document it finds the DB and update the fields.

But using your component I can just mail merge with DB once opened the fields are merged, but its not reference to the DB. So if change the data in the database it will not reflect in the second time opening the document.

Please let me know how to do like ms word datasource linking?


For this I don't want to run the application each time.


Thanks in Advance.

Hi

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

Thanks for your request. Unfortunately, there is no way to link document to Mail Merge DataSource using Aspose.Words. This is logged in our defect database as feature request #5170.

You can only perform Mail Merge using Aspose.Words programmatically as described here:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/perform-mail-merge.html

Best regards.

The issues you have found earlier (filed as 5170) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(85)

Hi,


I see that Feature request #5170 was ‘solved’ in an update, but can you give some example code on how to link a Word document to an existing datasource for mailmerge without the actual ‘Generate’?

I would like to give my users a document that has been linked to a datasource, with the correct mergefields in the document, but not yet generated so the user can manually alter some text before selecting in Word the ‘Merge to…’ option.

Best regards
Frans

Hi Frans,


Thanks for your inquiry. For example, you can connect an Excel spreadsheet as an external data source to your input Word template document via the Dynamic Data Exchange (DDE) system by using the code something like below:

Document doc = new Document(@“C:\Temp\Doc1.docx”);

string connectionString = “Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Temp\Book1.xlsx;Mode=Read;Extended Properties=“HDR=YES;IMEX=1;”;Jet OLEDB:System database=”";Jet OLEDB:Registry Path="";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don’t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False";<o:p></o:p>

string query = "SELECT * FROM Sheet1$";<o:p></o:p>

MailMergeSettings mms = doc.MailMergeSettings;<o:p></o:p>

mms.MainDocumentType = MailMergeMainDocumentType.MailingLabels;<o:p></o:p>

mms.DataType = MailMergeDataType.Native;<o:p></o:p>

mms.DataSource = @“C:\Temp\Book1.xlsx”;<o:p></o:p>

mms.ConnectString = connectionString;<o:p></o:p>

mms.Destination = MailMergeDestination.NewDocument;<o:p></o:p>

mms.Query = query;<o:p></o:p>

mms.LinkToQuery = false;<o:p></o:p>

mms.ViewMergedData = true;<o:p></o:p>

doc.Save(@“c:\Temp\out.docx”);


I hope, this helps.

PS: Sample document and spreadsheet are attached

Best regards,

Works perfectly! Thanks