├── .github └── workflows │ └── gitleaks.yaml ├── Create-Envelopes-for-mailing ├── Console-App-.NET-Core │ ├── Create-Envelopes-for-mailing.sln │ └── Create-Envelopes-for-mailing │ │ ├── Create-Envelopes-for-mailing.csproj │ │ ├── Program.cs │ │ └── Template.docx ├── Images │ ├── Envelopes-for-mailing-output.png │ └── Envelopes-for-mailing-template.png └── README.md ├── Create-and-send-email-messages ├── Console-App-.NET-Core │ ├── Create-and-send-email-messages.sln │ └── Create-and-send-email-messages │ │ ├── Create-and-send-email-messages.csproj │ │ ├── CustomerDetails.json │ │ ├── Program.cs │ │ └── Template.docx ├── Images │ ├── Create-and-send-email-messages-output.png │ └── Create-and-send-email-messages-template.png └── README.md ├── Create-personalized-letter ├── Console-App-.NET-Core │ ├── Create-personalized-letter.sln │ └── Create-personalized-letter │ │ ├── Create-personalized-letter.csproj │ │ ├── LetterTemplate.docx │ │ └── Program.cs ├── Images │ ├── Create-personalized-letter-output.png │ └── Create-personalized-letter-template.png └── README.md ├── Fit-photo-within-textbox ├── Console-App-.NET-Framework │ ├── Fit-photo-within-textbox.sln │ └── Fit-photo-within-textbox │ │ ├── App.config │ │ ├── Fit-photo-within-textbox.csproj │ │ ├── Logo.jpg │ │ ├── Program.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Sample.docx │ │ ├── Template.docx │ │ └── packages.config ├── Images │ ├── Fit-photo-within-textbox-output.png │ └── Fit-photo-within-textbox-template.png └── README.md ├── Generate-Barcode-labels ├── Console-APP-.NET-Core │ ├── Generate-Barcode-labels.sln │ └── Generate-Barcode-labels │ │ ├── Generate-Barcode-labels.csproj │ │ ├── Program.cs │ │ └── Template.docx ├── Console-App-.NET-Framework │ ├── Generate-Barcode-labels.sln │ └── Generate-Barcode-labels │ │ ├── App.config │ │ ├── Generate-Barcode-labels.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Template.docx │ │ └── packages.config ├── Images │ ├── Generate-Barcode-labels-output.png │ └── Generate-Barcode-labels-template.png └── README.md ├── Generate-multiple-Word-documents ├── Console-App-.NET-Framework │ ├── Generate-multiple-Word-documents.sln │ └── Generate-multiple-Word-documents │ │ ├── App.config │ │ ├── CustomerDetails.mdb │ │ ├── Generate-multiple-Word-documents.csproj │ │ ├── LetterTemplate.docx │ │ ├── Program.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ └── packages.config ├── Images │ ├── Generate-multiple-Word-documents-output.png │ └── Generate-multiple-Word-documents-template.png └── README.md ├── Generate-order-details-of-customer ├── Console-App-.NET-Core │ ├── Generate-order-details-of-customer.sln │ └── Generate-order-details-of-customer │ │ ├── CustomerDetails.xml │ │ ├── Generate-order-details-of-customer.csproj │ │ ├── Program.cs │ │ └── Template.docx ├── Images │ ├── Generate-order-details-of-customer-output.png │ └── Generate-order-details-of-customer-template.png └── README.md ├── Group-Mail-merge-using-Excel ├── Console-App-.NET-Core │ ├── Group-Mail-merge-using-Excel.sln │ └── Group-Mail-merge-using-Excel │ │ ├── Group-Mail-merge-using-Excel.csproj │ │ ├── Program.cs │ │ ├── StockDetails.xlsx │ │ └── Template.docx ├── Images │ ├── Group-Mail-merge-using-Excel-output.png │ └── Group-Mail-merge-using-Excel-template.png └── README.md ├── Images └── Mail-merge-in-Word-library.png ├── Product-catalog ├── Console-App-.NET-Core │ ├── Product-catalog.sln │ └── Product-catalog │ │ ├── Data │ │ ├── Apple Juice.png │ │ ├── Cherry.png │ │ ├── Cone.png │ │ ├── Grape Juice.png │ │ ├── Hot Soup.png │ │ ├── Strawberry.png │ │ ├── Tender Coconut.png │ │ └── Vennila.png │ │ ├── Product-catalog.csproj │ │ ├── Program.cs │ │ └── Template.docx ├── Images │ ├── Product-catalog-output.png │ └── Product-catalog-template.png └── README.md ├── README.md ├── Replace-Merge-field-with-HTML ├── Console-App-.NET-Framework │ ├── Replace-Merge-field-with-HTML.sln │ └── Replace-Merge-field-with-HTML │ │ ├── App.config │ │ ├── File.html │ │ ├── Program.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Replace-Merge-field-with-HTML.csproj │ │ ├── Template.docx │ │ └── packages.config ├── Images │ ├── Replace-Merge-field-with-HTML-output.png │ └── Replace-Merge-field-with-HTML-template.png └── README.md └── Start-each-record-on-new-page ├── Console-App-.NET-Core ├── Start-each-record-on-new-page.sln └── Start-each-record-on-new-page │ ├── Program.cs │ ├── Start-each-record-on-new-page.csproj │ └── Template.docx ├── Images ├── Start-each-record-on-new-page-output.png └── Start-each-record-on-new-page-template.png └── README.md /.github/workflows/gitleaks.yaml: -------------------------------------------------------------------------------- 1 | name: Secret Value found!! 2 | on: 3 | push: 4 | public: 5 | jobs: 6 | scan: 7 | name: gitleaks 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v3 12 | - name: Install the gitleaks 13 | run: wget https://github.com/zricethezav/gitleaks/releases/download/v8.15.2/gitleaks_8.15.2_linux_x64.tar.gz 14 | shell: pwsh 15 | - name: Extract the tar file 16 | run: tar xzvf gitleaks_8.15.2_linux_x64.tar.gz 17 | - name: Generate the report 18 | id: gitleaks 19 | run: $GITHUB_WORKSPACE/gitleaks detect -s $GITHUB_WORKSPACE -f json -r $GITHUB_WORKSPACE/leaksreport.json 20 | shell: bash 21 | continue-on-error: true 22 | - name: Setup NuGet.exe 23 | if: steps.gitleaks.outcome != 'success' 24 | uses: nuget/setup-nuget@v1 25 | with: 26 | nuget-version: latest 27 | - name: Install the dotnet 28 | if: steps.gitleaks.outcome != 'success' 29 | uses: actions/setup-dotnet@v3 30 | with: 31 | dotnet-version: '3.1.x' 32 | - name: Install the report tool packages 33 | if: steps.gitleaks.outcome != 'success' 34 | run: | 35 | nuget install "Syncfusion.Email" -source ${{ secrets.NexusFeedLink }} -ExcludeVersion 36 | dir $GITHUB_WORKSPACE/Syncfusion.Email/lib/netcoreapp3.1 37 | dotnet $GITHUB_WORKSPACE/Syncfusion.Email/lib/netcoreapp3.1/GitleaksReportMail.dll ${{ secrets.CITEAMCREDENTIALS }} "$GITHUB_REF_NAME" ${{ secrets.NETWORKCREDENTIALS }} ${{ secrets.NETWORKKEY }} "$GITHUB_WORKSPACE" ${{ secrets.ORGANIZATIONNAME }} 38 | exit 1 -------------------------------------------------------------------------------- /Create-Envelopes-for-mailing/Console-App-.NET-Core/Create-Envelopes-for-mailing.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.539 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create-Envelopes-for-mailing", "Create-Envelopes-for-mailing\Create-Envelopes-for-mailing.csproj", "{E2EA3F53-C833-470F-B9FA-973E88BD963A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {AEC106DA-724A-4C7B-B93C-560F32DF1F98} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Create-Envelopes-for-mailing/Console-App-.NET-Core/Create-Envelopes-for-mailing/Create-Envelopes-for-mailing.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | Create_Envelopes_for_mailing 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Create-Envelopes-for-mailing/Console-App-.NET-Core/Create-Envelopes-for-mailing/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | 7 | namespace Create_Envelopes_for_mailing 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | //Creates new Word document instance for Word processing 14 | using (WordDocument document = new WordDocument()) 15 | { 16 | //Opens the Word template document 17 | Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Template.docx")); 18 | document.Open(docStream, FormatType.Docx); 19 | docStream.Dispose(); 20 | 21 | //Gets the recipient details as "IEnumerable" collection of .NET objects 22 | List recipients = GetRecipients(); 23 | 24 | //Performs the mail merge 25 | document.MailMerge.Execute(recipients); 26 | 27 | //Saves the file in the given path 28 | docStream = File.Create(Path.GetFullPath(@"../../../Sample.docx")); 29 | document.Save(docStream, FormatType.Docx); 30 | docStream.Dispose(); 31 | } 32 | } 33 | 34 | #region Helper methods 35 | /// 36 | /// Gets the data to perform mail merge. 37 | /// 38 | /// 39 | private static List GetRecipients() 40 | { 41 | List recipients = new List(); 42 | //Initializes the recipient details 43 | recipients.Add(new Recipient("Nancy", "Davolio", "507 - 20th Ave. E.Apt. 2A", "Seattle", "WA", "98122", "USA")); 44 | recipients.Add(new Recipient("Andrew", "Fuller", "908 W. Capital Way", "Tacoma", "WA", "98401", "USA")); 45 | recipients.Add(new Recipient("Janet", "Leverling", "722 Moss Bay Blvd.", "Kirkland", "WA", "98033", "USA")); 46 | recipients.Add(new Recipient("Margaret", "Peacock", "4110 Old Redmond Rd.", "Redmond", "WA", "98052", "USA")); 47 | recipients.Add(new Recipient("Steven", "Buchanan", "14 Garrett Hil", "London", "", "SW1 8JR", "UK")); 48 | 49 | return recipients; 50 | } 51 | #endregion 52 | 53 | } 54 | 55 | #region Helper class 56 | /// 57 | /// Represents the Recipient details. 58 | /// 59 | class Recipient 60 | { 61 | #region Properties 62 | public string FirstName { get; set; } 63 | public string LastName { get; set; } 64 | public string Address { get; set; } 65 | public string City { get; set; } 66 | public string State { get; set; } 67 | public string ZipCode { get; set; } 68 | public string Country { get; set; } 69 | #endregion 70 | 71 | #region Constructor 72 | public Recipient(string firstName, string lastName, string address, string city, string state, string zipCode, string country) 73 | { 74 | FirstName = firstName; 75 | LastName = lastName; 76 | Address = address; 77 | City = city; 78 | State = state; 79 | ZipCode = zipCode; 80 | Country = country; 81 | } 82 | #endregion 83 | } 84 | #endregion 85 | } 86 | -------------------------------------------------------------------------------- /Create-Envelopes-for-mailing/Console-App-.NET-Core/Create-Envelopes-for-mailing/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-Envelopes-for-mailing/Console-App-.NET-Core/Create-Envelopes-for-mailing/Template.docx -------------------------------------------------------------------------------- /Create-Envelopes-for-mailing/Images/Envelopes-for-mailing-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-Envelopes-for-mailing/Images/Envelopes-for-mailing-output.png -------------------------------------------------------------------------------- /Create-Envelopes-for-mailing/Images/Envelopes-for-mailing-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-Envelopes-for-mailing/Images/Envelopes-for-mailing-template.png -------------------------------------------------------------------------------- /Create-Envelopes-for-mailing/README.md: -------------------------------------------------------------------------------- 1 | # Create envelopes for mailing in C# 2 | 3 | This example illustrates how to create envelopes for mailing to a list of recipients using the [Execute(IEnumerable dataSource)](https://help.syncfusion.com/cr/cref_files/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMerge~Execute(IEnumerable).html) API. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the envelopes for mailing as follows. 18 | 19 |

20 | Envelopes-for-mailing-output 21 |

22 | 23 | To generate envelopes, design your template Word document with the required layout, formatting, graphics, and merge fields to personalize information using Microsoft Word as follows. 24 | 25 |

26 | Envelopes-for-mailing-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Create-and-send-email-messages/Console-App-.NET-Core/Create-and-send-email-messages.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create-and-send-email-messages", "Create-and-send-email-messages\Create-and-send-email-messages.csproj", "{2071F614-2A3E-420E-B70B-433038A1B3DA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2071F614-2A3E-420E-B70B-433038A1B3DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {2071F614-2A3E-420E-B70B-433038A1B3DA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {2071F614-2A3E-420E-B70B-433038A1B3DA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {2071F614-2A3E-420E-B70B-433038A1B3DA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {861D988A-5C1D-4BFE-A1BA-BA5FAC2A5622} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Create-and-send-email-messages/Console-App-.NET-Core/Create-and-send-email-messages/Create-and-send-email-messages.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Create-and-send-email-messages/Console-App-.NET-Core/Create-and-send-email-messages/CustomerDetails.json: -------------------------------------------------------------------------------- 1 | { 2 | "Customers": [ 3 | { 4 | "CustomerName": "Paul Henriot", 5 | "Address": "59 rue de l'Abbaye", 6 | "City": "Reims", 7 | "PostalCode": "51100", 8 | "Country": "France", 9 | "Phone": "26.47.15.10", 10 | "OrderID": "10295", 11 | "OrderDate": "09/02/2018", 12 | "ExpectedDeliveryDate": "09/30/2018", 13 | "ShippedDate": "09/10/2018" 14 | }, 15 | { 16 | "CustomerName": "Maria Anders", 17 | "Address": "Obere Str. 57", 18 | "City": "Berlin", 19 | "PostalCode": "12209", 20 | "Country": "Germany", 21 | "Phone": "030-0074321", 22 | "OrderID": "10702", 23 | "OrderDate": "10/13/2018", 24 | "ExpectedDeliveryDate": "11/24/2018", 25 | "ShippedDate": "10/21/2018" 26 | }, 27 | { 28 | "CustomerName": "Pedro Afonso", 29 | "Address": "Av. dos Lusíadas, 23", 30 | "City": "São Paulo", 31 | "PostalCode": "05432-043", 32 | "Country": "Brazil", 33 | "Phone": "(11) 555-7647", 34 | "OrderID": "10969", 35 | "OrderDate": "03/23/2019", 36 | "ExpectedDeliveryDate": "04/20/2019", 37 | "ShippedDate": "03/30/2019" 38 | }, 39 | { 40 | "CustomerName": "Alexander Feuer", 41 | "Address": "Heerstr. 22", 42 | "City": "Leipzig", 43 | "PostalCode": "04179", 44 | "Country": "Germany", 45 | "Phone": "0342-023176", 46 | "OrderID": "10277", 47 | "OrderDate": "08/09/2018", 48 | "ExpectedDeliveryDate": "09/06/2018", 49 | "ShippedDate": "08/13/2018" 50 | }, 51 | { 52 | "CustomerName": "Sergio Gutiérrez", 53 | "Address": "Av. del Libertador 900", 54 | "City": "Buenos Aires", 55 | "PostalCode": "1010", 56 | "Country": "Argentina", 57 | "Phone": "(1) 123-5555", 58 | "OrderID": "10916", 59 | "OrderDate": "02/27/2019", 60 | "ExpectedDeliveryDate": "03/27/2019", 61 | "ShippedDate": "03/09/2019" 62 | } 63 | ] 64 | } -------------------------------------------------------------------------------- /Create-and-send-email-messages/Console-App-.NET-Core/Create-and-send-email-messages/Program.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using Syncfusion.DocIO; 3 | using Syncfusion.DocIO.DLS; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Net.Mail; 7 | 8 | namespace Create_and_send_email_messages 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //Creates new Word document instance for Word processing 15 | using (WordDocument template = new WordDocument()) 16 | { 17 | //Opens the Word template document 18 | Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Template.docx")); 19 | template.Open(docStream, FormatType.Docx); 20 | docStream.Dispose(); 21 | 22 | //Gets the recipient details as DataTable 23 | List recipients = GetRecipients(); 24 | foreach (var dataRecord in recipients) 25 | { 26 | //Clones the template document for creating new document for each record in the data source 27 | WordDocument document = template.Clone(); 28 | 29 | //Performs the mail merge 30 | document.MailMerge.Execute(new List() { dataRecord as Dictionary }); 31 | 32 | //Save the HTML file as string 33 | docStream = new MemoryStream(); 34 | document.SaveOptions.HtmlExportOmitXmlDeclaration = true; 35 | document.Save(docStream, FormatType.Html); 36 | //Releases the resources occupied by WordDocument instance 37 | document.Dispose(); 38 | docStream.Position = 0; 39 | StreamReader reader = new StreamReader(docStream); 40 | string mailBody = reader.ReadToEnd(); 41 | docStream.Dispose(); 42 | if (mailBody.StartsWith(")["OrderID"].ToString() + " has been shipped", mailBody); 47 | } 48 | } 49 | } 50 | #region Helper methods 51 | private static void SendEMail(string from, string recipients, string subject, string body) 52 | { 53 | //Creates the email message 54 | var emailMessage = new MailMessage(from, recipients); 55 | //Adds the subject for email 56 | emailMessage.Subject = subject; 57 | //Sets the HTML string as email body 58 | emailMessage.IsBodyHtml = true; 59 | emailMessage.Body = body; 60 | //Sends the email with prepared message 61 | using (var client = new SmtpClient()) 62 | { 63 | //Update your SMTP Server address here 64 | client.Host = "smtp.live.com"; 65 | client.UseDefaultCredentials = false; 66 | //Update your email credentials here 67 | client.Credentials = new System.Net.NetworkCredential(from, "password"); 68 | client.Port = 587; 69 | client.EnableSsl = true; 70 | client.Send(emailMessage); 71 | } 72 | } 73 | /// 74 | /// Gets the data to perform mail merge. 75 | /// 76 | /// 77 | private static List GetRecipients() 78 | { 79 | //Reads the JSON object from JSON file. 80 | JObject jsonObject = JObject.Parse(File.ReadAllText(@"../../../CustomerDetails.json")); 81 | //Converts JSON object to Dictionary. 82 | IDictionary data = GetData(jsonObject); 83 | return data["Customers"] as List; 84 | } 85 | 86 | /// 87 | /// Gets data from JSON object. 88 | /// 89 | /// JSON object. 90 | /// Dictionary of data. 91 | private static IDictionary GetData(JObject jsonObject) 92 | { 93 | Dictionary dictionary = new Dictionary(); 94 | foreach (var item in jsonObject) 95 | { 96 | object keyValue = null; 97 | if (item.Value is JArray) 98 | keyValue = GetData((JArray)item.Value); 99 | else if (item.Value is JToken) 100 | keyValue = ((JToken)item.Value).ToObject(); 101 | dictionary.Add(item.Key, keyValue); 102 | } 103 | return dictionary; 104 | } 105 | /// 106 | /// Gets array of items from JSON array. 107 | /// 108 | /// JSON array. 109 | /// List of objects. 110 | private static List GetData(JArray jArray) 111 | { 112 | List jArrayItems = new List(); 113 | foreach (var item in jArray) 114 | { 115 | object keyValue = null; 116 | if (item is JObject) 117 | keyValue = GetData((JObject)item); 118 | jArrayItems.Add(keyValue); 119 | } 120 | return jArrayItems; 121 | } 122 | #endregion 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Create-and-send-email-messages/Console-App-.NET-Core/Create-and-send-email-messages/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-and-send-email-messages/Console-App-.NET-Core/Create-and-send-email-messages/Template.docx -------------------------------------------------------------------------------- /Create-and-send-email-messages/Images/Create-and-send-email-messages-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-and-send-email-messages/Images/Create-and-send-email-messages-output.png -------------------------------------------------------------------------------- /Create-and-send-email-messages/Images/Create-and-send-email-messages-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-and-send-email-messages/Images/Create-and-send-email-messages-template.png -------------------------------------------------------------------------------- /Create-and-send-email-messages/README.md: -------------------------------------------------------------------------------- 1 | # Create and send email messages in C# 2 | 3 | This example shows how to create and send email messages to the recipients from JSON data by converting the mail merged Word document to HTML using [Syncfusion® Word library](https://www.syncfusion.com/word-framework/net/word-library?utm_source=github&utm_medium=listing&utm_campaign=mail-merge-examples) (Essential® DocIO). 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Enter your login details and recipient mail IDs to send messages. 14 | 15 | 5. Run the application. 16 | 17 | # Screenshots 18 | 19 | By running this application, you can create and send email messages as follows. 20 | 21 |

22 |  Create-and-send-email-messages-output 23 |

24 | 25 | To create and send bulk email messages, design your template Word document with the required contents and merge fields using Microsoft Word as follows. 26 | 27 |

28 | Create-and-send-email-messages-template.png 29 |

30 | 31 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Create-personalized-letter/Console-App-.NET-Core/Create-personalized-letter.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create-personalized-letter", "Create-personalized-letter\Create-personalized-letter.csproj", "{93B2DB03-A8C6-45F3-AD35-D425E05FBCBB}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {93B2DB03-A8C6-45F3-AD35-D425E05FBCBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {93B2DB03-A8C6-45F3-AD35-D425E05FBCBB}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {93B2DB03-A8C6-45F3-AD35-D425E05FBCBB}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {93B2DB03-A8C6-45F3-AD35-D425E05FBCBB}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {6EBDF01F-98DC-45F7-957E-C6806C627CA2} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Create-personalized-letter/Console-App-.NET-Core/Create-personalized-letter/Create-personalized-letter.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Create-personalized-letter/Console-App-.NET-Core/Create-personalized-letter/LetterTemplate.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-personalized-letter/Console-App-.NET-Core/Create-personalized-letter/LetterTemplate.docx -------------------------------------------------------------------------------- /Create-personalized-letter/Console-App-.NET-Core/Create-personalized-letter/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using System.IO; 4 | 5 | namespace Create_personalized_letter 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | //Opens the Word template document 12 | Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../LetterTemplate.docx")); 13 | WordDocument document = new WordDocument(docStream, FormatType.Docx); 14 | docStream.Dispose(); 15 | 16 | //Loads the string arrays with field names and values for mail merge 17 | string[] fieldNames = { "ContactName", "CompanyName", "Address", "City", "Country", "Phone" }; 18 | string[] fieldValues = { "Nancy Davolio", "Syncfusion", "507 - 20th Ave. E.Apt. 2A", "Seattle, WA", "USA", "(206) 555-9857-x5467" }; 19 | 20 | //Performs the mail merge 21 | document.MailMerge.Execute(fieldNames, fieldValues); 22 | 23 | //Saves the Word document as DOCX format 24 | docStream = File.Create(Path.GetFullPath(@"../../../Sample.docx")); 25 | document.Save(docStream, FormatType.Docx); 26 | docStream.Dispose(); 27 | //Releases the resources occupied by WordDocument instance 28 | document.Dispose(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Create-personalized-letter/Images/Create-personalized-letter-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-personalized-letter/Images/Create-personalized-letter-output.png -------------------------------------------------------------------------------- /Create-personalized-letter/Images/Create-personalized-letter-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Create-personalized-letter/Images/Create-personalized-letter-template.png -------------------------------------------------------------------------------- /Create-personalized-letter/README.md: -------------------------------------------------------------------------------- 1 | # Create personalized letters in C# 2 | 3 | This example illustrates how to personalize letters using an array of field names with its values as data source by using the [Execute(string[] fieldNames, string[] fieldValues)](https://help.syncfusion.com/cr/cref_files/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMerge~Execute(String[],String[]).html) API. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get a personalized letter as follows. 18 | 19 |

20 | Create-personalized-letter-output 21 |

22 | 23 | To personalize letters, design your template Word document with the required content and merge fields using Microsoft Word as follows. 24 | 25 |

26 | Create-personalized-letter-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fit-photo-within-textbox", "Fit-photo-within-textbox\Fit-photo-within-textbox.csproj", "{7FFCFFDE-3AB9-447B-90CA-4E31103757BE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {7FFCFFDE-3AB9-447B-90CA-4E31103757BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {7FFCFFDE-3AB9-447B-90CA-4E31103757BE}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {7FFCFFDE-3AB9-447B-90CA-4E31103757BE}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {7FFCFFDE-3AB9-447B-90CA-4E31103757BE}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {CBBFD906-282F-49F8-9090-9C0AC88E8D36} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Fit-photo-within-textbox.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7FFCFFDE-3AB9-447B-90CA-4E31103757BE} 8 | Exe 9 | Fit_photo_within_textbox 10 | Fit-photo-within-textbox 11 | v4.6.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | ..\packages\Syncfusion.Compression.Base.29.1.33\lib\net462\Syncfusion.Compression.Base.dll 39 | 40 | 41 | ..\packages\Syncfusion.DocIO.WinForms.29.1.33\lib\net462\Syncfusion.DocIO.Base.dll 42 | 43 | 44 | ..\packages\Syncfusion.Licensing.29.1.33\lib\net462\Syncfusion.Licensing.dll 45 | 46 | 47 | ..\packages\Syncfusion.OfficeChart.Base.29.1.33\lib\net462\Syncfusion.OfficeChart.Base.dll 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Logo.jpg -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO.DLS; 2 | using System.Drawing; 3 | using System.IO; 4 | 5 | namespace Fit_photo_within_textbox 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | //Opens the template document 12 | using (WordDocument document = new WordDocument(@"../../Template.docx")) 13 | { 14 | //Uses the mail merge events handler for image fields 15 | document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_ProductImage); 16 | //Specifies the field names and field values 17 | string[] fieldNames = new string[] { "Photo" }; 18 | string[] fieldValues = new string[] { "Logo.jpg" }; 19 | //Executes the mail merge with groups 20 | document.MailMerge.Execute(fieldNames, fieldValues); 21 | //Unhooks mail merge events handler 22 | document.MailMerge.MergeImageField -= new MergeImageFieldEventHandler(MergeField_ProductImage); 23 | //Saves the Word document instance 24 | document.Save(@"../../Sample.docx"); 25 | } 26 | System.Diagnostics.Process.Start(Path.GetFullPath(@"../../Sample.docx")); 27 | } 28 | 29 | #region Helper method 30 | /// 31 | /// Binds the image from file system and fit within text box during Mail merge process by using MergeImageFieldEventHandler. 32 | /// 33 | /// 34 | /// 35 | public static void MergeField_ProductImage(object sender, MergeImageFieldEventArgs args) 36 | { 37 | //Binds image from file system during mail merge 38 | if (args.FieldName == "Photo") 39 | { 40 | string ProductFileName = args.FieldValue.ToString(); 41 | //Gets the image from file system 42 | args.Image = Image.FromFile(@"../../" + ProductFileName); 43 | //Gets the picture, to be merged for image merge field 44 | WPicture picture = args.Picture; 45 | //Gets the text box format 46 | WTextBoxFormat textBoxFormat = (args.CurrentMergeField.OwnerParagraph.OwnerTextBody.Owner as WTextBox).TextBoxFormat; 47 | //Resizes the picture to fit within text box 48 | float scalePercentage = 100; 49 | if (picture.Width != textBoxFormat.Width) 50 | { 51 | //Calculates value for width scale factor 52 | scalePercentage = textBoxFormat.Width / picture.Width * 100; 53 | //This will resize the width 54 | picture.WidthScale *= scalePercentage / 100; 55 | } 56 | scalePercentage = 100; 57 | if (picture.Height != textBoxFormat.Height) 58 | { 59 | //Calculates value for height scale factor 60 | scalePercentage = textBoxFormat.Height / picture.Height * 100; 61 | //This will resize the height 62 | picture.HeightScale *= scalePercentage / 100; 63 | } 64 | } 65 | } 66 | #endregion 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Fit-photo-within-textbox")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Fit-photo-within-textbox")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7ffcffde-3ab9-447b-90ca-4e31103757be")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Sample.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Sample.docx -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/Template.docx -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Console-App-.NET-Framework/Fit-photo-within-textbox/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Images/Fit-photo-within-textbox-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Fit-photo-within-textbox/Images/Fit-photo-within-textbox-output.png -------------------------------------------------------------------------------- /Fit-photo-within-textbox/Images/Fit-photo-within-textbox-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Fit-photo-within-textbox/Images/Fit-photo-within-textbox-template.png -------------------------------------------------------------------------------- /Fit-photo-within-textbox/README.md: -------------------------------------------------------------------------------- 1 | # Fit the photo within the text box using Mail merge in C# 2 | 3 | This example illustrates how to fit the photo within the text box in Word document using Mail merge. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the output Word document as follows. 18 | 19 |

20 | Fit-photo-within-textbox-output 21 |

22 | 23 | To fit the photo within the text box, design your template Word document with the required content and merge fields using Microsoft Word as follows. 24 | 25 |

26 | Fit-photo-within-textbox-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-APP-.NET-Core/Generate-Barcode-labels.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30709.64 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generate-Barcode-labels", "Generate-Barcode-labels\Generate-Barcode-labels.csproj", "{767B845C-92BC-4112-B603-53D7E22BDC3C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {767B845C-92BC-4112-B603-53D7E22BDC3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {767B845C-92BC-4112-B603-53D7E22BDC3C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {767B845C-92BC-4112-B603-53D7E22BDC3C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {767B845C-92BC-4112-B603-53D7E22BDC3C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {D37D89FC-B391-4802-87FD-8CB0CA37543D} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-APP-.NET-Core/Generate-Barcode-labels/Generate-Barcode-labels.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | Generate_Barcode_labels 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-APP-.NET-Core/Generate-Barcode-labels/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using Syncfusion.Pdf.Barcode; 4 | using Syncfusion.Pdf.Graphics; 5 | using System; 6 | using System.Data; 7 | using System.IO; 8 | 9 | namespace Generate_Barcode_labels 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | //Opens an existing document from stream through constructor of `WordDocument` class 16 | FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"../../../Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 17 | WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic); 18 | //Creates mail merge events handler for image fields 19 | document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(InsertBarcode); 20 | //Gets data to perform mail merge 21 | DataTable table = GetDataTable(); 22 | //Performs the mail merge 23 | document.MailMerge.ExecuteGroup(table); 24 | 25 | //Saves and closes the Word document instance 26 | FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Result.docx"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); 27 | document.Save(outputStream, FormatType.Docx); 28 | outputStream.Dispose(); 29 | document.Close(); 30 | } 31 | 32 | #region Helper methods 33 | /// 34 | /// Inserts barcode in the Word document 35 | /// 36 | private static void InsertBarcode(object sender, MergeImageFieldEventArgs args) 37 | { 38 | if (args.FieldName == "Barcode") 39 | { 40 | //Generates barcode image for field value. 41 | Stream imageStream= GenerateBarcodeImage(args.FieldValue.ToString()); 42 | //Sets barcode image stream for merge field 43 | args.ImageStream = imageStream; 44 | } 45 | } 46 | /// 47 | /// Generates barcode image stream. 48 | /// 49 | /// Barcode text 50 | /// Barcode image stream 51 | private static Stream GenerateBarcodeImage(string barcodeText) 52 | { 53 | //Initialize a new PdfCode39Barcode instance 54 | PdfCode39Barcode barcode = new PdfCode39Barcode(); 55 | //Set the height and text for barcode 56 | barcode.BarHeight = 45; 57 | barcode.Text = barcodeText; 58 | //Convert the barcode to image 59 | Stream imageStream = barcode.ToImage(new Syncfusion.Drawing.SizeF(145, 45)); 60 | return imageStream; 61 | } 62 | 63 | /// 64 | /// Gets the data to perform mail merge 65 | /// 66 | /// 67 | private static DataTable GetDataTable() 68 | { 69 | // List of products name. 70 | string[] products = { "Apple Juice", "Grape Juice", "Hot Soup", "Tender Coconut", "Vennila", "Strawberry", "Cherry", "Cone", 71 | "Butter", "Milk", "Cheese", "Salt", "Honey", "Soap", "Chocolate", "Edible Oil", "Spices", "Paneer", "Curd", "Bread", "Olive oil", "Vinegar", "Sports Drinks", 72 | "Vegetable Juice", "Sugar", "Flour", "Jam", "Cake", "Brownies", "Donuts", "Egg", "Tooth Brush", "Talcum powder", "Detergent Soap", "Room Spray", "Tooth paste"}; 73 | 74 | DataTable table = new DataTable("Product_PriceList"); 75 | 76 | // Add fields to the Product_PriceList table. 77 | table.Columns.Add("ProductName"); 78 | table.Columns.Add("Price"); 79 | table.Columns.Add("Barcode"); 80 | DataRow row; 81 | 82 | int Id = 10001; 83 | // Inserting values to the tables. 84 | foreach (string product in products) 85 | { 86 | row = table.NewRow(); 87 | row["ProductName"] = product; 88 | switch (product) 89 | { 90 | case "Apple Juice": 91 | row["Price"] = "$12.00"; 92 | break; 93 | case "Grape Juice": 94 | case "Milk": 95 | row["Price"] = "$15.00"; 96 | break; 97 | case "Hot Soup": 98 | row["Price"] = "$20.00"; 99 | break; 100 | case "Tender coconut": 101 | case "Cheese": 102 | row["Price"] = "$10.00"; 103 | break; 104 | case "Vennila Ice Cream": 105 | row["Price"] = "$15.00"; 106 | break; 107 | case "Strawberry": 108 | case "Butter": 109 | row["Price"] = "$18.00"; 110 | break; 111 | case "Cherry": 112 | case "Salt": 113 | row["Price"] = "$25.00"; 114 | break; 115 | default: 116 | row["Price"] = "$20.00"; 117 | break; 118 | } 119 | //Add barcode text 120 | row["Barcode"] = Id.ToString(); 121 | table.Rows.Add(row); 122 | Id++; 123 | } 124 | return table; 125 | } 126 | #endregion 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-APP-.NET-Core/Generate-Barcode-labels/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-Barcode-labels/Console-APP-.NET-Core/Generate-Barcode-labels/Template.docx -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generate-Barcode-labels", "Generate-Barcode-labels\Generate-Barcode-labels.csproj", "{0C31B82D-7738-499A-BA4E-3B727B4D7946}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {B48CCAC7-7EC4-4E41-9D7C-5723D23B2136} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels/Generate-Barcode-labels.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0C31B82D-7738-499A-BA4E-3B727B4D7946} 8 | Exe 9 | Generate-Barcode-labels 10 | Generate-Barcode-labels 11 | v4.6.2 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Syncfusion.Compression.Base.29.1.33\lib\net462\Syncfusion.Compression.Base.dll 38 | 39 | 40 | ..\packages\Syncfusion.DocIO.WinForms.29.1.33\lib\net462\Syncfusion.DocIO.Base.dll 41 | 42 | 43 | ..\packages\Syncfusion.Licensing.29.1.33\lib\net462\Syncfusion.Licensing.dll 44 | 45 | 46 | ..\packages\Syncfusion.OfficeChart.Base.29.1.33\lib\net462\Syncfusion.OfficeChart.Base.dll 47 | 48 | 49 | ..\packages\Syncfusion.Pdf.WinForms.29.1.33\lib\net462\Syncfusion.Pdf.Base.dll 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using Syncfusion.Pdf.Barcode; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | 8 | namespace Generate_Barcode_labels 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //Opens the template document 15 | WordDocument document = new WordDocument(Path.GetFullPath(@"../../Template.docx")); 16 | //Creates mail merge events handler for image fields 17 | document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(InsertBarcode); 18 | //Gets data to perform mail merge 19 | DataTable table = GetDataTable(); 20 | //Performs the mail merge 21 | document.MailMerge.ExecuteGroup(table); 22 | 23 | //Saves and closes the Word document instance 24 | document.Save(Path.GetFullPath(@"../../Sample.docx")); 25 | document.Close(); 26 | } 27 | 28 | #region Helper methods 29 | /// 30 | /// Inserts barcode in the Word document 31 | /// 32 | private static void InsertBarcode(object sender, MergeImageFieldEventArgs args) 33 | { 34 | if (args.FieldName == "Barcode") 35 | { 36 | //Generates barcode image for field value. 37 | Image barcodeImage = GenerateBarcodeImage(args.FieldValue.ToString()); 38 | //Sets barcode image for merge field 39 | args.Image = barcodeImage; 40 | } 41 | } 42 | /// 43 | /// Generates barcode image. 44 | /// 45 | /// Barcode text 46 | /// Barcode image 47 | private static Image GenerateBarcodeImage(string barcodeText) 48 | { 49 | //Initialize a new PdfCode39Barcode instance 50 | PdfCode39Barcode barcode = new PdfCode39Barcode(); 51 | //Set the height and text for barcode 52 | barcode.BarHeight = 45; 53 | barcode.Text = barcodeText; 54 | //Convert the barcode to image 55 | Image barcodeImage = barcode.ToImage(new SizeF(145, 45)); 56 | return barcodeImage; 57 | } 58 | 59 | /// 60 | /// Gets the data to perform mail merge 61 | /// 62 | /// 63 | private static DataTable GetDataTable() 64 | { 65 | // List of products name. 66 | string[] products = { "Apple Juice", "Grape Juice", "Hot Soup", "Tender Coconut", "Vennila", "Strawberry", "Cherry", "Cone", 67 | "Butter", "Milk", "Cheese", "Salt", "Honey", "Soap", "Chocolate", "Edible Oil", "Spices", "Paneer", "Curd", "Bread", "Olive oil", "Vinegar", "Sports Drinks", 68 | "Vegetable Juice", "Sugar", "Flour", "Jam", "Cake", "Brownies", "Donuts", "Egg", "Tooth Brush", "Talcum powder", "Detergent Soap", "Room Spray", "Tooth paste"}; 69 | 70 | DataTable table = new DataTable("Product_PriceList"); 71 | 72 | // Add fields to the Product_PriceList table. 73 | table.Columns.Add("ProductName"); 74 | table.Columns.Add("Price"); 75 | table.Columns.Add("Barcode"); 76 | DataRow row; 77 | 78 | int Id =10001; 79 | // Inserting values to the tables. 80 | foreach (string product in products) 81 | { 82 | row = table.NewRow(); 83 | row["ProductName"] = product; 84 | switch (product) 85 | { 86 | case "Apple Juice": 87 | row["Price"] = "$12.00"; 88 | break; 89 | case "Grape Juice": 90 | case "Milk": 91 | row["Price"] = "$15.00"; 92 | break; 93 | case "Hot Soup": 94 | row["Price"] = "$20.00"; 95 | break; 96 | case "Tender coconut": 97 | case "Cheese": 98 | row["Price"] = "$10.00"; 99 | break; 100 | case "Vennila Ice Cream": 101 | row["Price"] = "$15.00"; 102 | break; 103 | case "Strawberry": 104 | case "Butter": 105 | row["Price"] = "$18.00"; 106 | break; 107 | case "Cherry": 108 | case "Salt": 109 | row["Price"] = "$25.00"; 110 | break; 111 | default: 112 | row["Price"] = "$20.00"; 113 | break; 114 | } 115 | //Add barcode text 116 | row["Barcode"] = Id.ToString(); 117 | table.Rows.Add(row); 118 | Id++; 119 | } 120 | return table; 121 | } 122 | #endregion 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Event-for-Mail-merge-field")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Event-for-Mail-merge-field")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0c31b82d-7738-499a-ba4e-3b727b4d7946")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels/Template.docx -------------------------------------------------------------------------------- /Generate-Barcode-labels/Console-App-.NET-Framework/Generate-Barcode-labels/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Generate-Barcode-labels/Images/Generate-Barcode-labels-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-Barcode-labels/Images/Generate-Barcode-labels-output.png -------------------------------------------------------------------------------- /Generate-Barcode-labels/Images/Generate-Barcode-labels-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-Barcode-labels/Images/Generate-Barcode-labels-template.png -------------------------------------------------------------------------------- /Generate-Barcode-labels/README.md: -------------------------------------------------------------------------------- 1 | # Generate barcode labels in C# 2 | 3 | This example shows how to generate a barcode using [Syncfusion® PDF library](https://www.syncfusion.com/pdf-framework/net/pdf-library?utm_source=github&utm_medium=listing&utm_campaign=mail-merge-examples) and insert the generated barcode as an image into the Word document with [MergeImageField](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMerge~MergeImageField_EV.html) event using [Syncfusion® Word library](https://www.syncfusion.com/word-framework/net/word-library?utm_source=github&utm_medium=listing&utm_campaign=mail-merge-examples) (Essential® DocIO). 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the barcode labels as follows. 18 | 19 |

20 | Generate-Barcode-labels-output 21 |

22 | 23 | To generate barcode labels, design your template Word document with the required layout, formatting, graphics, and merge fields using Microsoft Word as follows. 24 | 25 | **Note:** In this Word template document, [NEXT](https://support.office.com/en-us/article/field-codes-next-field-3862fad6-0297-411a-a4e7-6ff5bcf178fd?ui=en-US&rs=en-US&ad=US) field is inserted at end of each cell and this field instructs to merge the next record from the data source. You can view the NEXT field by opening this template document in Microsoft Word application and press Alt+F9 shortcut key to toggle field codes. 26 | 27 |

28 | Generate-Barcode-labels-template 29 |

30 | 31 | 32 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generate-multiple-Word-documents", "Generate-multiple-Word-documents\Generate-multiple-Word-documents.csproj", "{0C31B82D-7738-499A-BA4E-3B727B4D7946}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0C31B82D-7738-499A-BA4E-3B727B4D7946}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {B48CCAC7-7EC4-4E41-9D7C-5723D23B2136} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/CustomerDetails.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/CustomerDetails.mdb -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/Generate-multiple-Word-documents.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0C31B82D-7738-499A-BA4E-3B727B4D7946} 8 | Exe 9 | Generate_multiple_Word_documents 10 | Generate-multiple-Word-documents 11 | v4.6.2 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Syncfusion.Compression.Base.29.1.33\lib\net462\Syncfusion.Compression.Base.dll 38 | 39 | 40 | ..\packages\Syncfusion.DocIO.WinForms.29.1.33\lib\net462\Syncfusion.DocIO.Base.dll 41 | 42 | 43 | ..\packages\Syncfusion.Licensing.29.1.33\lib\net462\Syncfusion.Licensing.dll 44 | 45 | 46 | ..\packages\Syncfusion.OfficeChart.Base.29.1.33\lib\net462\Syncfusion.OfficeChart.Base.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/LetterTemplate.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/LetterTemplate.docx -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using System.Collections.Generic; 4 | using System.Data; 5 | using System.Data.OleDb; 6 | using System.IO; 7 | 8 | namespace Generate_multiple_Word_documents 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //Creates new Word document instance for Word processing 15 | using (WordDocument template = new WordDocument()) 16 | { 17 | //Opens the Word template document 18 | template.Open(Path.GetFullPath(@"../../LetterTemplate.docx"), FormatType.Docx); 19 | 20 | //Gets the recipient details as DataTable 21 | DataTable recipients = GetRecipients(); 22 | 23 | //Creates folder for saving generated documents 24 | if (!Directory.Exists(Path.GetFullPath(@"../../Result/"))) 25 | Directory.CreateDirectory(Path.GetFullPath(@"../../Result/")); 26 | foreach (DataRow dataRow in recipients.Rows) 27 | { 28 | //Clones the template document for creating new document for each record in the data source 29 | WordDocument document = template.Clone(); 30 | 31 | //Performs the mail merge 32 | document.MailMerge.Execute(dataRow); 33 | 34 | //Save the file in the given path 35 | document.Save(Path.GetFullPath(@"../../Result/Letter_" + dataRow.ItemArray[2].ToString() + ".docx"), FormatType.Docx); 36 | //Releases the resources occupied by WordDocument instance 37 | document.Dispose(); 38 | } 39 | } 40 | } 41 | #region Helper methods 42 | /// 43 | /// Gets the data to perform mail merge. 44 | /// 45 | /// 46 | private static DataTable GetRecipients() 47 | { 48 | //Creates new DataTable instance 49 | DataTable table = new DataTable(); 50 | //Loads the database 51 | OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"../../CustomerDetails.mdb"); 52 | //Opens the database connection 53 | conn.Open(); 54 | OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from Customers", conn); 55 | //Gets the data from the database 56 | adapter.Fill(table); 57 | //Releases the memory occupied by database connection 58 | adapter.Dispose(); 59 | conn.Close(); 60 | return table; 61 | } 62 | #endregion 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Generate-multiple-Word-documents")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Generate-multiple-Word-documents")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0c31b82d-7738-499a-ba4e-3b727b4d7946")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Console-App-.NET-Framework/Generate-multiple-Word-documents/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Images/Generate-multiple-Word-documents-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-multiple-Word-documents/Images/Generate-multiple-Word-documents-output.png -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/Images/Generate-multiple-Word-documents-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-multiple-Word-documents/Images/Generate-multiple-Word-documents-template.png -------------------------------------------------------------------------------- /Generate-multiple-Word-documents/README.md: -------------------------------------------------------------------------------- 1 | # Generate multiple Word documents in C# 2 | 3 | This example shows how to generate multiple Word documents for each record in [DataTable](https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable?view=netframework-4.8) using the [Execute(DataRow row)](https://help.syncfusion.com/cr/cref_files/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMerge~Execute(DataRow).html) API. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get multiple Word documents as follows. 18 | 19 |

20 | Generate-multiple-Word-documents-output 21 |

22 | 23 | To generate multiple Word documents, design your template Word document with the required content and merge fields using Microsoft Word as follows. 24 | 25 |

26 | Generate-multiple-Word-documents-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Generate-order-details-of-customer/Console-App-.NET-Core/Generate-order-details-of-customer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generate-order-details-of-customer", "Generate-order-details-of-customer\Generate-order-details-of-customer.csproj", "{280D7941-5A84-4E1D-BFF8-E8C57486EF16}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {280D7941-5A84-4E1D-BFF8-E8C57486EF16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {280D7941-5A84-4E1D-BFF8-E8C57486EF16}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {280D7941-5A84-4E1D-BFF8-E8C57486EF16}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {280D7941-5A84-4E1D-BFF8-E8C57486EF16}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {BB0AC061-F9FB-41D6-8E58-C8F9939D98FB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Generate-order-details-of-customer/Console-App-.NET-Core/Generate-order-details-of-customer/CustomerDetails.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Paul Henriot 5 |
59 rue de l'Abbaye
6 | Reims 7 | 51100 8 | France 9 | 26.47.15.10 10 | 11 | Paul Henriot 12 | 10248 13 | 07/04/2018 14 | 08/01/2018 15 | 07/16/2018 16 | 17 | 10248 18 | Queso Cabrales 19 | $14.00 20 | 12 21 | 22 | 23 | 10248 24 | Singaporean Hokkien Fried Mee 25 | $9.80 26 | 10 27 | 28 | 29 | 10248 30 | Mozzarella di Giovanni 31 | $34.80 32 | 5 33 | 34 | 35 | 36 | Paul Henriot 37 | 10274 38 | 08/06/2018 39 | 09/03/2018 40 | 08/16/2018 41 | 42 | 10274 43 | Fløtemysost 44 | $17.20 45 | 20 46 | 47 | 48 | 10274 49 | Mozzarella di Giovanni 50 | $27.80 51 | 7 52 | 53 | 54 | 55 | Paul Henriot 56 | 10295 57 | 09/02/2018 58 | 09/30/2018 59 | 09/10/2018 60 | 61 | 10295 62 | Gnocchi di nonna Alice 63 | $30.40 64 | 4 65 | 66 | 67 |
68 | 69 | Maria Anders 70 |
Obere Str. 57
71 | Berlin 72 | 12209 73 | Germany 74 | 030-0074321 75 | 76 | Maria Anders 77 | 10643 78 | 08/25/2018 79 | 09/22/2018 80 | 09/02/2018 81 | 82 | 10643 83 | Rössle Sauerkraut 84 | $45.60 85 | 15 86 | 87 | 88 | 10643 89 | Chartreuse verte 90 | $18.00 91 | 21 92 | 93 | 94 | 10643 95 | Spegesild 96 | $12.00 97 | 2 98 | 99 | 100 | 101 | Maria Anders 102 | 10702 103 | 10/13/2018 104 | 11/24/2018 105 | 10/21/2018 106 | 107 | 10702 108 | Aniseed Syrup 109 | $10.00 110 | 6 111 | 112 | 113 | 10702 114 | Lakkalikööri 115 | $18.00 116 | 15 117 | 118 | 119 |
120 | 121 | Pedro Afonso 122 |
Av. dos Lusíadas, 23
123 | São Paulo 124 | 05432-043 125 | Brazil 126 | (11) 555-7647 127 | 128 | Pedro Afonso 129 | 10290 130 | 08/27/2018 131 | 09/24/2018 132 | 09/03/2018 133 | 134 | 10290 135 | Chef Anton's Gumbo Mix 136 | $17.00 137 | 20 138 | 139 | 140 | 10290 141 | Thüringer Rostbratwurst 142 | $99.00 143 | 15 144 | 145 | 146 | 10290 147 | Maxilaku 148 | $16.00 149 | 15 150 | 151 | 152 | 153 | Pedro Afonso 154 | 10969 155 | 03/23/2019 156 | 04/20/2019 157 | 03/30/2019 158 | 159 | 10969 160 | Spegesild 161 | $12.00 162 | 9 163 | 164 | 165 |
166 | 167 | Alexander Feuer 168 |
Heerstr. 22
169 | Leipzig 170 | 04179 171 | Germany 172 | 0342-023176 173 | 174 | Alexander Feuer 175 | 10277 176 | 08/09/2018 177 | 09/06/2018 178 | 08/13/2018 179 | 180 | 10277 181 | Rössle Sauerkraut 182 | $36.40 183 | 20 184 | 185 | 186 | 10277 187 | Tarte au sucre 188 | $39.40 189 | 12 190 | 191 | 192 |
193 | 194 | Sergio Gutiérrez 195 |
Av. del Libertador 900
196 | Buenos Aires 197 | 1010 198 | Argentina 199 | (1) 123-5555 200 | 201 | Sergio Gutiérrez 202 | 10716 203 | 10/24/2018 204 | 11/21/2018 205 | 10/27/2018 206 | 207 | 10716 208 | Sir Rodney's Scones 209 | $10.00 210 | 5 211 | 212 | 213 | 10716 214 | Manjimup Dried Apples 215 | $53.00 216 | 7 217 | 218 | 219 | 10716 220 | Sirop d'érable 221 | $28.50 222 | 10 223 | 224 | 225 | 226 | Sergio Gutiérrez 227 | 10916 228 | 02/27/2019 229 | 03/27/2019 230 | 03/09/2019 231 | 232 | 10916 233 | Pavlova 234 | $17.45 235 | 6 236 | 237 | 238 | 10916 239 | Mascarpone Fabioli 240 | $32.00 241 | 6 242 | 243 | 244 | 10916 245 | Ravioli Angelo 246 | $19.50 247 | 20 248 | 249 | 250 |
251 |
-------------------------------------------------------------------------------- /Generate-order-details-of-customer/Console-App-.NET-Core/Generate-order-details-of-customer/Generate-order-details-of-customer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Generate-order-details-of-customer/Console-App-.NET-Core/Generate-order-details-of-customer/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Dynamic; 6 | using System.IO; 7 | using System.Xml; 8 | 9 | namespace Generate_order_details_of_customer 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | //Creates new Word document instance for Word processing 16 | using (WordDocument document = new WordDocument()) 17 | { 18 | //Opens the Word template document 19 | Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Template.docx")); 20 | document.Open(docStream, FormatType.Docx); 21 | docStream.Dispose(); 22 | 23 | //Performs the mail merge for group 24 | document.MailMerge.ExecuteNestedGroup(GetRelationalData()); 25 | //Removes empty page at the end of Word document 26 | RemoveEmptyPage(document); 27 | 28 | //Saves the file in the given path 29 | docStream = File.Create(Path.GetFullPath(@"../../../Sample.docx")); 30 | document.Save(docStream, FormatType.Docx); 31 | docStream.Dispose(); 32 | } 33 | } 34 | 35 | #region Helper Methods 36 | /// 37 | /// Gets the relational data to perform mail merge 38 | /// 39 | /// 40 | static MailMergeDataTable GetRelationalData() 41 | { 42 | List customers = new List(); 43 | //Gets data from XML 44 | Stream xmlStream = File.OpenRead(Path.GetFullPath(@"../../../CustomerDetails.xml")); 45 | XmlDocument xmlDocument = new XmlDocument(); 46 | xmlDocument.Load(xmlStream); 47 | xmlStream.Dispose(); 48 | 49 | ExpandoObject customer = new ExpandoObject(); 50 | GetDataAsExpandoObject((xmlDocument as XmlNode).LastChild, ref customer); 51 | customers = (((customer as IDictionary)["CustomerDetails"] as List)[0] as IDictionary)["Customers"] as List; 52 | //Creates an instance of "MailMergeDataTable" by specifying mail merge group name and "IEnumerable" collection 53 | MailMergeDataTable dataTable = new MailMergeDataTable("Customers", customers); 54 | return dataTable; 55 | } 56 | 57 | /// 58 | /// Gets the data as ExpandoObject. 59 | /// 60 | /// The reader. 61 | /// 62 | /// reader 63 | /// Unexpected xml tag + reader.LocalName 64 | private static void GetDataAsExpandoObject(XmlNode node, ref ExpandoObject dynamicObject) 65 | { 66 | if (node.InnerText == node.InnerXml) 67 | dynamicObject.TryAdd(node.LocalName, node.InnerText); 68 | else 69 | { 70 | List childObjects; 71 | if ((dynamicObject as IDictionary).ContainsKey(node.LocalName)) 72 | childObjects = (dynamicObject as IDictionary)[node.LocalName] as List; 73 | else 74 | { 75 | childObjects = new List(); 76 | dynamicObject.TryAdd(node.LocalName, childObjects); 77 | } 78 | ExpandoObject childObject = new ExpandoObject(); 79 | foreach (XmlNode childNode in (node as XmlNode).ChildNodes) 80 | { 81 | GetDataAsExpandoObject(childNode, ref childObject); 82 | } 83 | childObjects.Add(childObject); 84 | } 85 | } 86 | /// 87 | /// Removes empty paragraphs from the end of Word document. 88 | /// 89 | /// The Word document 90 | private static void RemoveEmptyPage(WordDocument document) 91 | { 92 | WTextBody textBody = document.LastSection.Body; 93 | 94 | //A flag to determine any renderable item found in the Word document. 95 | bool IsRenderableItem = false; 96 | //Iterates text body items. 97 | for (int itemIndex = textBody.ChildEntities.Count - 1; itemIndex >= 0 && !IsRenderableItem; itemIndex--) 98 | { 99 | //Check item is empty paragraph and removes it. 100 | if (textBody.ChildEntities[itemIndex] is WParagraph) 101 | { 102 | WParagraph paragraph = textBody.ChildEntities[itemIndex] as WParagraph; 103 | //Iterates into paragraph 104 | for (int pIndex = paragraph.Items.Count - 1; pIndex >= 0; pIndex--) 105 | { 106 | ParagraphItem paragraphItem = paragraph.Items[pIndex]; 107 | 108 | //If page break found in end of document, then remove it to preserve contents in same page 109 | if ((paragraphItem is Break && (paragraphItem as Break).BreakType == BreakType.PageBreak)) 110 | paragraph.Items.RemoveAt(pIndex); 111 | 112 | //Check paragraph contains any renderable items. 113 | else if (!(paragraphItem is BookmarkStart || paragraphItem is BookmarkEnd)) 114 | { 115 | IsRenderableItem = true; 116 | //Found renderable item and break the iteration. 117 | break; 118 | } 119 | } 120 | //Remove empty paragraph and the paragraph with bookmarks only 121 | if (paragraph.Items.Count == 0 || !IsRenderableItem) 122 | textBody.ChildEntities.RemoveAt(itemIndex); 123 | } 124 | } 125 | } 126 | #endregion 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Generate-order-details-of-customer/Console-App-.NET-Core/Generate-order-details-of-customer/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-order-details-of-customer/Console-App-.NET-Core/Generate-order-details-of-customer/Template.docx -------------------------------------------------------------------------------- /Generate-order-details-of-customer/Images/Generate-order-details-of-customer-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-order-details-of-customer/Images/Generate-order-details-of-customer-output.png -------------------------------------------------------------------------------- /Generate-order-details-of-customer/Images/Generate-order-details-of-customer-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Generate-order-details-of-customer/Images/Generate-order-details-of-customer-template.png -------------------------------------------------------------------------------- /Generate-order-details-of-customer/README.md: -------------------------------------------------------------------------------- 1 | # Generate order details of customer in C# 2 | 3 | This example illustrates how to generate order details of each customer by performing **nested mail merge** operation for a specified region using [MailMergeDataTable](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMergeDataTable.html) as the data source by [ExecuteNestedGroup(MailMergeDataTable dataTable)](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMerge~ExecuteNestedGroup(MailMergeDataTable).html) API. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the order details in a Word document as follows. 18 | 19 |

20 | Generate-order-details-of-customer-output 21 |

22 | 23 | To create order details by nested mail merge operation, design your template Word document with the nested group of merge fields using Microsoft Word. In the below template, Customers is the owner group and it has two child groups, Orders and Products. 24 | 25 |

26 | Generate-order-details-of-customer-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/Console-App-.NET-Core/Group-Mail-merge-using-Excel.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Group-Mail-merge-using-Excel", "Group-Mail-merge-using-Excel\Group-Mail-merge-using-Excel.csproj", "{CA9C066E-B845-4240-A17D-CB8B82A038E9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {CA9C066E-B845-4240-A17D-CB8B82A038E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {CA9C066E-B845-4240-A17D-CB8B82A038E9}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {CA9C066E-B845-4240-A17D-CB8B82A038E9}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {CA9C066E-B845-4240-A17D-CB8B82A038E9}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {A920224D-CDA7-4DCE-995D-ADCB17CE8C32} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/Console-App-.NET-Core/Group-Mail-merge-using-Excel/Group-Mail-merge-using-Excel.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/Console-App-.NET-Core/Group-Mail-merge-using-Excel/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using Syncfusion.XlsIO; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | 7 | namespace Group_Mail_merge_using_Excel 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | //Creates new Word document instance for Word processing 14 | using (WordDocument document = new WordDocument()) 15 | { 16 | //Opens the Word template document 17 | Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Template.docx")); 18 | document.Open(docStream, FormatType.Docx); 19 | docStream.Dispose(); 20 | 21 | //Performs the mail merge for group 22 | document.MailMerge.ExecuteGroup(GetData()); 23 | 24 | //Updates fields in the document 25 | document.UpdateDocumentFields(); 26 | 27 | //Saves the file in the given path 28 | docStream = File.Create(Path.GetFullPath(@"../../../Sample.docx")); 29 | document.Save(docStream, FormatType.Docx); 30 | docStream.Dispose(); 31 | } 32 | } 33 | #region Helper Method 34 | /// 35 | /// Gets the data from Excel for mail merge 36 | /// 37 | /// 38 | private static MailMergeDataTable GetData() 39 | { 40 | //Creates new excel engine 41 | ExcelEngine excelEngine = new ExcelEngine(); 42 | //Creates new excel application 43 | IApplication application = excelEngine.Excel; 44 | 45 | //Opens the excel to extract data for mail merge 46 | Stream excelStream = File.OpenRead(Path.GetFullPath(@"../../../StockDetails.xlsx")); 47 | IWorkbook workbook = application.Workbooks.Open(excelStream); 48 | excelStream.Dispose(); 49 | 50 | //Exports data from worksheet to .NET objects 51 | IWorksheet sheet = workbook.Worksheets[0]; 52 | List stockDetails = sheet.ExportData(1, 1, 31, 5); 53 | workbook.Close(); 54 | excelEngine.Dispose(); 55 | return new MailMergeDataTable("StockDetails", stockDetails); 56 | } 57 | #endregion 58 | } 59 | #region Helper Class 60 | public class StockDetail 61 | { 62 | public string TradeNo { get; set; } 63 | public string CompanyName { get; set; } 64 | public string CostPrice { get; set; } 65 | public string SharesCount { get; set; } 66 | public string SalesPrice { get; set; } 67 | 68 | public StockDetail() 69 | { 70 | } 71 | } 72 | #endregion 73 | } 74 | -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/Console-App-.NET-Core/Group-Mail-merge-using-Excel/StockDetails.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Group-Mail-merge-using-Excel/Console-App-.NET-Core/Group-Mail-merge-using-Excel/StockDetails.xlsx -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/Console-App-.NET-Core/Group-Mail-merge-using-Excel/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Group-Mail-merge-using-Excel/Console-App-.NET-Core/Group-Mail-merge-using-Excel/Template.docx -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/Images/Group-Mail-merge-using-Excel-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Group-Mail-merge-using-Excel/Images/Group-Mail-merge-using-Excel-output.png -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/Images/Group-Mail-merge-using-Excel-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Group-Mail-merge-using-Excel/Images/Group-Mail-merge-using-Excel-template.png -------------------------------------------------------------------------------- /Group-Mail-merge-using-Excel/README.md: -------------------------------------------------------------------------------- 1 | # Group mail merge using Excel in C# 2 | 3 | This example illustrates how to import data from Excel Spreadsheet using [Syncfusion® Excel library](https://www.syncfusion.com/excel-framework/net/excel-library?utm_source=github&utm_medium=listing&utm_campaign=mail-merge-examples) (Essential® XlsIO) and use that data for mail merge in the Word document using [Syncfusion® Word library](https://www.syncfusion.com/word-framework/net/word-library?utm_source=github&utm_medium=listing&utm_campaign=mail-merge-examples) (Essential® DocIO). 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the stock market report as follows. 18 | 19 |

20 | Group-Mail-merge-using-Excel-output 21 |

22 | 23 | To generate reports in a Word document, design your template Word document with the required layout, formatting, graphics, and merge fields using Microsoft Word as follows. 24 | 25 |

26 | Group-Mail-merge-using-Excel-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. 30 | -------------------------------------------------------------------------------- /Images/Mail-merge-in-Word-library.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Images/Mail-merge-in-Word-library.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.539 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Product-catalog", "Product-catalog\Product-catalog.csproj", "{E2EA3F53-C833-470F-B9FA-973E88BD963A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E2EA3F53-C833-470F-B9FA-973E88BD963A}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {AEC106DA-724A-4C7B-B93C-560F32DF1F98} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Apple Juice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Apple Juice.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Cherry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Cherry.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Cone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Cone.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Grape Juice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Grape Juice.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Hot Soup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Hot Soup.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Strawberry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Strawberry.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Tender Coconut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Tender Coconut.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Vennila.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Data/Vennila.png -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Product-catalog.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | Product_catalog 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO; 2 | using Syncfusion.DocIO.DLS; 3 | using Syncfusion.Drawing; 4 | using System.Data; 5 | using System.IO; 6 | 7 | namespace Product_catalog 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | //Creates new Word document instance for Word processing 14 | using (WordDocument document = new WordDocument()) 15 | { 16 | //Opens the Word template document 17 | Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Template.docx")); 18 | document.Open(docStream, FormatType.Docx); 19 | docStream.Dispose(); 20 | //Get the data set 21 | DataSet ds = GetData(); 22 | //Using Merge events to do conditional formatting during runtime 23 | document.MailMerge.MergeField += new MergeFieldEventHandler(AlternateRows_MergeField); 24 | document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_ProductImage); 25 | //Execute Mail Merge with groups 26 | document.MailMerge.ExecuteGroup(ds.Tables["Products"]); 27 | document.MailMerge.ExecuteGroup(ds.Tables["Product_PriceList"]); 28 | //Saves and closes the Word document 29 | docStream = File.Create(Path.GetFullPath(@"../../../Sample.docx")); 30 | document.Save(docStream, FormatType.Docx); 31 | docStream.Dispose(); 32 | } 33 | } 34 | 35 | #region Helper Methods 36 | /// 37 | /// Gets the data to perform mail merge 38 | /// 39 | private static DataSet GetData() 40 | { 41 | // Create a DataSet. 42 | DataSet ds = new DataSet(); 43 | //List of Syncfusion products name 44 | string[] products = { "Apple Juice", "Grape Juice", "Hot Soup", "Tender Coconut", "Vennila", "Strawberry", "Cherry", "Cone" }; 45 | //Add new Tables to the data set 46 | DataRow row; 47 | ds.Tables.Add(); 48 | ds.Tables.Add(); 49 | //Add fields to the Product_PriceList table. 50 | ds.Tables[0].TableName = "Product_PriceList"; 51 | ds.Tables[0].Columns.Add("ProductName"); 52 | ds.Tables[0].Columns.Add("Price"); 53 | //Add fields to the Products table. 54 | ds.Tables[1].TableName = "Products"; 55 | ds.Tables[1].Columns.Add("SNO"); 56 | ds.Tables[1].Columns.Add("ProductName"); 57 | ds.Tables[1].Columns.Add("ProductImage"); 58 | int count = 0; 59 | //Insert values to the table row. 60 | foreach (string product in products) 61 | { 62 | row = ds.Tables["Product_PriceList"].NewRow(); 63 | row["ProductName"] = product; 64 | switch (product) 65 | { 66 | case "Apple Juice": 67 | row["Price"] = "$12.00"; break; 68 | case "Grape Juice": 69 | row["Price"] = "$15.00"; break; 70 | case "Hot Soup": 71 | row["Price"] = "$20.00"; break; 72 | case "Tender coconut": 73 | row["Price"] = "$10.00"; break; 74 | case "Vennila Ice Cream": 75 | row["Price"] = "$15.00"; break; 76 | case "Strawberry": 77 | row["Price"] = "$18.00"; break; 78 | case "Cherry": 79 | row["Price"] = "$25.00"; break; 80 | default: 81 | row["Price"] = "$20.00"; break; 82 | } 83 | ds.Tables["Product_PriceList"].Rows.Add(row); 84 | count++; 85 | row = ds.Tables["Products"].NewRow(); 86 | row["SNO"] = count.ToString(); 87 | row["ProductName"] = product; 88 | row["ProductImage"] = string.Concat(product, ".png"); 89 | ds.Tables["Products"].Rows.Add(row); 90 | } 91 | return ds; 92 | } 93 | #endregion 94 | 95 | #region Event Handlers 96 | /// 97 | /// Method to handle MergeField event. 98 | /// 99 | private static void AlternateRows_MergeField(object sender, MergeFieldEventArgs args) 100 | { 101 | // Conditionally format data during mail merge 102 | if (args.RowIndex % 2 != 0) 103 | { 104 | //Formats the merged text of alternate row with different text color. 105 | args.CharacterFormat.TextColor = Color.FromArgb(196, 89, 17); 106 | } 107 | } 108 | /// 109 | /// Method to handle MergeImageField event. 110 | /// 111 | private static void MergeField_ProductImage(object sender, MergeImageFieldEventArgs args) 112 | { 113 | // Gets the image from file system during mail merge 114 | if (args.FieldName == "ProductImage") 115 | { 116 | //Gets the image file name 117 | string ProductFileName = args.FieldValue.ToString(); 118 | //Gets image from file system 119 | FileStream imageStream = new FileStream(@"../../../Data/" + ProductFileName, FileMode.Open, FileAccess.Read); 120 | //Sets the image for mail merge 121 | args.ImageStream = imageStream; 122 | } 123 | } 124 | #endregion 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Product-catalog/Console-App-.NET-Core/Product-catalog/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Console-App-.NET-Core/Product-catalog/Template.docx -------------------------------------------------------------------------------- /Product-catalog/Images/Product-catalog-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Images/Product-catalog-output.png -------------------------------------------------------------------------------- /Product-catalog/Images/Product-catalog-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Product-catalog/Images/Product-catalog-template.png -------------------------------------------------------------------------------- /Product-catalog/README.md: -------------------------------------------------------------------------------- 1 | # Product catalog in C# 2 | 3 | This example illustrates how to generate a product catalog by performing mail merge in the Word document with formatting the merged text using the [MergeField](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMerge~MergeField_EV.html) event and update the image using [MergeImageField](https://help.syncfusion.com/cr/cref_files/file-formats/Syncfusion.DocIO.Base~Syncfusion.DocIO.DLS.MailMerge~MergeImageField_EV.html) event. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the product catalog as follows. 18 | 19 |

20 | Product-catalog-output 21 |

22 | 23 | To generate product catalog, design your template Word document with the required layout, formatting, graphics, and merge fields using Microsoft Word as follows. 24 |

25 | Product-catalog-template 26 |

27 | 28 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mail merge Examples 2 | 3 | This repository contains examples that illustrates how to mail merge Word documents in C# and VB.NET using Syncfusion’s [.NET Word library](https://www.syncfusion.com/word-framework/net/word-library?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) (Essential® DocIO) without Microsoft Word or Office interop dependencies. 4 | 5 | # Mail merge in Word documents 6 | 7 | Mail merge is a process of merging data (replacing merge fields) from a data source into the template Word document. 8 | 9 | The Syncfusion® [Word library](https://www.syncfusion.com/word-framework/net/word-library?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) (Essential® DocIO) has a powerful [mail merge](https://www.syncfusion.com/word-framework/net/word-library/mail-merge?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) API to generate personalized reports like letters, pre-addressed envelopes, address labels, invoice, payroll, and more. It performs mail merge faster in a batch process without Microsoft Word or Office interop dependencies. The generated reports can be saved as a Word document, PDF, image, HTML, and more. 10 | 11 |

12 | Mail-merge-in-Word-library 13 |

14 | 15 | # Key Features 16 | 17 | - [Envelopes for mailing in C#](Create-Envelopes-for-mailing/) - Create envelopes for mailings to the list of recipients. 18 | 19 | - [Generate multiple Word documents in C#](Generate-multiple-Word-documents/) - Create a batch of personalized letters as individual document for each record. 20 | 21 | - [Create and send email messages in C#](Create-and-send-email-messages/) - Create and send email messages by converting merged document to HTML. 22 | 23 | - [Personalized letters in C#](Create-personalized-letter/) - Create personalized letters for selected recipient from the mailing list. 24 | 25 | - [Order details of a customer in C#](Generate-order-details-of-customer/) - Generate order details of a customer using nested mail merge. 26 | 27 | - [Barcode labels in C#](Generate-Barcode-labels/) - Generate a barcode labels for grocery store. 28 | 29 | - [Mail merge using Excel Spreadsheet in C#](Group-Mail-merge-using-Excel/) - Import data from Excel Spreadsheet and generate a report. 30 | 31 | - [Product catalog in C#](Product-catalog/) - Generate a product catalog and formatting the merged text. 32 | 33 | - [Replace merge field with HTML in C#](Replace-Merge-field-with-HTML/) - Replace merge field with HTML string using mail merge. 34 | 35 | - [Fit the photo within text box in C#](Fit-photo-within-textbox/) - Fit the photo within the text box in the Word document using mail merge. 36 | 37 | - [Start each record on a new page in C#](Start-each-record-on-new-page/) - Generate each record in new page while executing group mail merge. 38 | 39 | # Screenshots 40 | 41 | **Envelopes for mailing** 42 | 43 |

44 | Envelopes-for-mailing in C# 45 |

46 | 47 | **Batch of personalized letters** 48 | 49 |

50 | Generate-multiple-Word-documents in C# 51 |

52 | 53 | **Barcode labels** 54 | 55 |

56 | Barcode-labels in C# 57 |

58 | 59 | **Replace merge field with HTML** 60 | 61 |

62 | Replace-Merge-field-with-HTML in C# 63 |

64 | 65 | **Fit photo within text box** 66 | 67 |

68 | Fit-photo-within-textbox in C# 69 |

70 | 71 | **Start each record on a new page** 72 | 73 |

74 | Start-each-record-on-new-page in C# 75 |

76 | 77 | ## Syncfusion® .NET Word Library 78 | The Syncfusion® DocIO is a [.NET Word library](https://www.syncfusion.com/document-processing/word-framework/net/word-library?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) allows you to add advanced Word document processing functionalities to any .NET application and does not require Microsoft Word application to be installed in the machine. It is a non-UI component that provides a full-fledged document instance model similar to the Microsoft Office COM libraries to iterate with the document elements explicitly and perform necessary manipulation. 79 | 80 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), where you can find basic Word document processing options along with the features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), [merge](https://help.syncfusion.com/file-formats/docio/word-document/merging-word-documents?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), [split](https://help.syncfusion.com/file-formats/docio/word-document/split-word-documents?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) and [compare documents](https://help.syncfusion.com/file-formats/docio/word-document/compare-word-documents?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) the Word documents, and most importantly, the [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) and [Image](https://help.syncfusion.com/file-formats/docio/word-to-image?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) conversions with code examples. 81 | 82 | Compatible Microsoft Word Versions 83 | ---------------------------------- 84 | 85 | * Microsoft Word 97-2003 86 | * Microsoft Word 2007 87 | * Microsoft Word 2010 88 | * Microsoft Word 2013 89 | * Microsoft Word 2016 90 | * Microsoft Word 2019 91 | * Microsoft 365 92 | 93 | Supported File Formats 94 | ---------------------- 95 | 96 | * Creates, reads, and edits popular text file formats like [DOC](https://help.syncfusion.com/file-formats/docio/word-file-formats?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples#doc-to-docx-and-docx-to-doc), DOT, [DOCM](https://help.syncfusion.com/file-formats/docio/word-file-formats?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples#macros), DOTM, [DOCX](https://help.syncfusion.com/file-formats/docio/word-file-formats?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples#doc-to-docx-and-docx-to-doc), [DOTX](https://help.syncfusion.com/file-formats/docio/word-file-formats?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples#templates), [HTML](https://help.syncfusion.com/file-formats/docio/html?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), [RTF](https://help.syncfusion.com/file-formats/docio/rtf?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), [TXT](https://help.syncfusion.com/file-formats/docio/text?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), and [XML (WordML)](https://help.syncfusion.com/file-formats/docio/word-file-formats#word-processing-xml-xml?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples). 97 | * Converts Word documents also to [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), [Image](https://help.syncfusion.com/file-formats/docio/word-to-image?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples), and [ODT](https://help.syncfusion.com/file-formats/docio/word-to-odt?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) files. 98 | 99 | ## How to run the examples 100 | - Download this project to a location in your disk. 101 | - Open the solution file using Visual Studio. 102 | - Rebuild the solution to install the required NuGet packages. 103 | - Run the application. 104 | 105 | 106 | ## Resources 107 | 108 | - **Product page:** [Syncfusion® Word Framework](https://www.syncfusion.com/document-processing/word-framework/net?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) 109 | - **Documentation:** [Mail merge using Syncfusion® Word library](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) 110 | - **GitHub Examples:** [Syncfusion® Word library examples](https://github.com/SyncfusionExamples/DocIO-Examples?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) 111 | - **Online demo:** [Syncfusion® Word library - Online demos](https://ej2.syncfusion.com/aspnetcore/DocIO/SalesInvoice?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) 112 | 113 | ## Support and feedback 114 | For any other queries, reach our [Syncfusion® support team](https://support.syncfusion.com/?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) or post the queries through the [community forums](https://www.syncfusion.com/forums?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples). 115 | 116 | Request new feature through [Syncfusion® feedback portal](https://www.syncfusion.com/feedback?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples). 117 | 118 | ## License 119 | This is a commercial product and requires a paid license for possession or use. Syncfusion's licensed software, including this component, is subject to the terms and conditions of [Syncfusion's EULA](https://www.syncfusion.com/license/studio/22.2.5/syncfusion_essential_studio_eula.pdf?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples). You can purchase a licnense [here](https://www.syncfusion.com/sales/products?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples) or start a free 30-day trial [here](https://www.syncfusion.com/account/manage-trials/start-trials?utm_source=github&utm_medium=listing&utm_campaign=github-github-docio-examples). -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-Merge-field-with-HTML", "Replace-Merge-field-with-HTML\Replace-Merge-field-with-HTML.csproj", "{07622DC9-E645-42EB-ABCE-5D8FB4940A89}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {07622DC9-E645-42EB-ABCE-5D8FB4940A89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {07622DC9-E645-42EB-ABCE-5D8FB4940A89}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {07622DC9-E645-42EB-ABCE-5D8FB4940A89}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {07622DC9-E645-42EB-ABCE-5D8FB4940A89}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E0C4527C-D611-4F19-B7EF-F9C263649B0F} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/File.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
    5 |
  • Mountain-200
  • 6 |
  • Mountain-300
  • 7 |
  • Road-150
  • 8 |
9 |
10 | 11 | -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/Program.cs: -------------------------------------------------------------------------------- 1 | using Syncfusion.DocIO.DLS; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.IO; 5 | 6 | namespace Replace_Merge_field_with_HTML 7 | { 8 | class Program 9 | { 10 | static Dictionary> paraToInsertHTML = new Dictionary>(); 11 | static void Main(string[] args) 12 | { 13 | //Opens the template document. 14 | using (WordDocument document = new WordDocument(Path.GetFullPath(@"../../Template.docx"))) 15 | { 16 | //Creates mail merge events handler to replace merge field with HTML. 17 | document.MailMerge.MergeField += new MergeFieldEventHandler(MergeFieldEvent); 18 | //Gets data to perform mail merge. 19 | DataTable table = GetDataTable(); 20 | //Performs the mail merge. 21 | document.MailMerge.Execute(table); 22 | //Append HTML to paragraph. 23 | InsertHtml(); 24 | //Removes mail merge events handler. 25 | document.MailMerge.MergeField -= new MergeFieldEventHandler(MergeFieldEvent); 26 | //Saves the Word document instance. 27 | document.Save(Path.GetFullPath(@"../../Sample.docx")); 28 | } 29 | System.Diagnostics.Process.Start(Path.GetFullPath(@"../../Sample.docx")); 30 | } 31 | 32 | #region Helper methods 33 | /// 34 | /// Replaces merge field with HTML string by using MergeFieldEventHandler. 35 | /// 36 | /// 37 | /// 38 | public static void MergeFieldEvent(object sender, MergeFieldEventArgs args) 39 | { 40 | if (args.TableName.Equals("HTML")) 41 | { 42 | if (args.FieldName.Equals("ProductList")) 43 | { 44 | //Gets the current merge field owner paragraph. 45 | WParagraph paragraph = args.CurrentMergeField.OwnerParagraph; 46 | //Gets the current merge field index in the current paragraph. 47 | int mergeFieldIndex = paragraph.ChildEntities.IndexOf(args.CurrentMergeField); 48 | //Maintain HTML in collection. 49 | Dictionary fieldValues = new Dictionary(); 50 | fieldValues.Add(mergeFieldIndex, args.FieldValue.ToString()); 51 | //Maintain paragraph in collection. 52 | paraToInsertHTML.Add(paragraph, fieldValues); 53 | //Set field value as empty. 54 | args.Text = string.Empty; 55 | } 56 | } 57 | } 58 | /// 59 | /// Gets the data to perform mail merge 60 | /// 61 | /// 62 | private static DataTable GetDataTable() 63 | { 64 | DataTable dataTable = new DataTable("HTML"); 65 | dataTable.Columns.Add("CustomerName"); 66 | dataTable.Columns.Add("Address"); 67 | dataTable.Columns.Add("Phone"); 68 | dataTable.Columns.Add("ProductList"); 69 | DataRow datarow = dataTable.NewRow(); 70 | dataTable.Rows.Add(datarow); 71 | datarow["CustomerName"] = "Nancy Davolio"; 72 | datarow["Address"] = "59 rue de I'Abbaye, Reims 51100, France"; 73 | datarow["Phone"] = "1-888-936-8638"; 74 | //Reads HTML string from the file. 75 | string htmlString = File.ReadAllText(@"../../File.html"); 76 | datarow["ProductList"] = htmlString; 77 | return dataTable; 78 | } 79 | /// 80 | /// Append HTML to paragraph. 81 | /// 82 | private static void InsertHtml() 83 | { 84 | //Iterates through each item in the dictionary. 85 | foreach (KeyValuePair> dictionaryItems in paraToInsertHTML) 86 | { 87 | WParagraph paragraph = dictionaryItems.Key as WParagraph; 88 | Dictionary values = dictionaryItems.Value as Dictionary; 89 | //Iterates through each value in the dictionary. 90 | foreach (KeyValuePair valuePair in values) 91 | { 92 | int index = valuePair.Key; 93 | string fieldValue = valuePair.Value; 94 | //Inserts HTML string at the same position of mergefield in Word document. 95 | paragraph.OwnerTextBody.InsertXHTML(fieldValue, paragraph.OwnerTextBody.ChildEntities.IndexOf(paragraph), index); 96 | } 97 | } 98 | paraToInsertHTML.Clear(); 99 | } 100 | #endregion 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Replace-Merge-field-with-HTML")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Replace-Merge-field-with-HTML")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("07622dc9-e645-42eb-abce-5d8fb4940a89")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/Replace-Merge-field-with-HTML.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {07622DC9-E645-42EB-ABCE-5D8FB4940A89} 8 | Exe 9 | Replace_Merge_field_with_HTML 10 | Replace-Merge-field-with-HTML 11 | v4.6.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | ..\packages\Syncfusion.Compression.Base.29.1.33\lib\net462\Syncfusion.Compression.Base.dll 39 | 40 | 41 | ..\packages\Syncfusion.DocIO.WinForms.29.1.33\lib\net462\Syncfusion.DocIO.Base.dll 42 | 43 | 44 | ..\packages\Syncfusion.Licensing.29.1.33\lib\net462\Syncfusion.Licensing.dll 45 | 46 | 47 | ..\packages\Syncfusion.OfficeChart.Base.29.1.33\lib\net462\Syncfusion.OfficeChart.Base.dll 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/Template.docx -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Console-App-.NET-Framework/Replace-Merge-field-with-HTML/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Images/Replace-Merge-field-with-HTML-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Replace-Merge-field-with-HTML/Images/Replace-Merge-field-with-HTML-output.png -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/Images/Replace-Merge-field-with-HTML-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Replace-Merge-field-with-HTML/Images/Replace-Merge-field-with-HTML-template.png -------------------------------------------------------------------------------- /Replace-Merge-field-with-HTML/README.md: -------------------------------------------------------------------------------- 1 | # Replace merge field with HTML string using Mail merge in C# 2 | 3 | This example illustrates how to replace merge field with HTML string using Mail merge. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the output Word document as follows. 18 | 19 |

20 | Replace-Merge-field-with-HTML-output 21 |

22 | 23 | To replace merge fields with HTML string, design your template Word document with the required content and merge fields using Microsoft Word as follows. 24 | 25 |

26 | Replace-Merge-field-with-HTML-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. -------------------------------------------------------------------------------- /Start-each-record-on-new-page/Console-App-.NET-Core/Start-each-record-on-new-page.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Start-each-record-on-new-page", "Start-each-record-on-new-page\Start-each-record-on-new-page.csproj", "{E214E65C-980A-46F5-8207-6D02212A49F5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E214E65C-980A-46F5-8207-6D02212A49F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E214E65C-980A-46F5-8207-6D02212A49F5}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E214E65C-980A-46F5-8207-6D02212A49F5}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E214E65C-980A-46F5-8207-6D02212A49F5}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {404A7F36-0167-4219-AE4D-2B0626CEB7E3} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Start-each-record-on-new-page/Console-App-.NET-Core/Start-each-record-on-new-page/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using Syncfusion.DocIO; 4 | using Syncfusion.DocIO.DLS; 5 | 6 | namespace Start_each_record_on_new_page 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | using (FileStream fileStream = new FileStream(Path.GetFullPath(@"../../../Template.docx"), FileMode.Open)) 13 | { 14 | //Loads an existing Word document. 15 | using (WordDocument document = new WordDocument(fileStream, FormatType.Automatic)) 16 | { 17 | //Gets the invoice details as “IEnumerable” collection. 18 | List invoice = GetInvoice(); 19 | //Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. 20 | MailMergeDataTable dataTable = new MailMergeDataTable("Invoice", invoice); 21 | //Enables the flag to start each record in new page. 22 | document.MailMerge.StartAtNewPage = true; 23 | //Performs Mail merge. 24 | document.MailMerge.ExecuteNestedGroup(dataTable); 25 | //Creates file stream. 26 | using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Result.docx"), FileMode.Create, FileAccess.ReadWrite)) 27 | { 28 | //Saves the Word document to file stream. 29 | document.Save(outputFileStream, FormatType.Docx); 30 | } 31 | } 32 | } 33 | } 34 | 35 | #region Helper method 36 | /// 37 | /// Get the data to perform mail merge. 38 | /// 39 | public static List GetInvoice() 40 | { 41 | //Creates invoice details. 42 | List invoices = new List(); 43 | 44 | List orders = new List(); 45 | orders.Add(new Orders("10248", "Vins et alcools Chevalier", "59 rue de l'Abbaye", "Reims", "51100", "France", "VINET", "59 rue de l'Abbaye", "51100", "Reims", "France", "Steven Buchanan", "Vins et alcools Chevalier", "1996-07-04T00:00:00-04:00", "1996-08-01T00:00:00-04:00", "1996-07-16T00:00:00-04:00", "Federal Shipping")); 46 | 47 | List order = new List(); 48 | order.Add(new Order("1", "Chai", "14.4", "45", "0.2", "518.4")); 49 | order.Add(new Order("2", "Boston Crab Meat", "14.7", "40", "0.2", "470.4")); 50 | 51 | List orderTotals = new List(); 52 | orderTotals.Add(new OrderTotals("440", "32.8", "472.38")); 53 | 54 | invoices.Add(new Invoice(orders, order, orderTotals)); 55 | 56 | orders = new List(); 57 | orders.Add(new Orders("10249", "Toms Spezialitäten", "Luisenstr. 48", "Münster", "51100", "Germany", "TOMSP", "Luisenstr. 48", "51100", "Münster", "Germany", "Michael Suyama", "Toms Spezialitäten", "1996-07-04T00:00:00-04:00", "1996-08-01T00:00:00-04:00", "1996-07-16T00:00:00-04:00", "Speedy Express")); 58 | 59 | order = new List(); 60 | order.Add(new Order("1", "Chai", "18", "45", "0.2", "618.4")); 61 | order.Add(new Order("4", "Alice Mutton", "39", "100", "0", "3900")); 62 | 63 | orderTotals = new List(); 64 | orderTotals.Add(new OrderTotals("1863.4", "11.61", "1875.01")); 65 | 66 | invoices.Add(new Invoice(orders, order, orderTotals)); 67 | 68 | orders = new List(); 69 | orders.Add(new Orders("10250", "Hanari Carnes", "Rua do Paço, 67", "Rio de Janeiro", "05454-876", "Brazil", "VINET", "Rua do Paço, 67", "51100", "Rio de Janeiro", "Brazil", "Margaret Peacock", "Hanari Carnes", "1996-07-04T00:00:00-04:00", "1996-08-01T00:00:00-04:00", "1996-07-16T00:00:00-04:00", "United Package")); 70 | 71 | order = new List(); 72 | order.Add(new Order("65", "Louisiana Fiery Hot Pepper Sauce", "16.8", "15", "0.15", "214.2")); 73 | order.Add(new Order("51", "Manjimup Dried Apples", "42.4", "35", "0.15", "1261.4")); 74 | 75 | orderTotals = new List(); 76 | orderTotals.Add(new OrderTotals("1552.6", "65.83", "1618.43")); 77 | 78 | invoices.Add(new Invoice(orders, order, orderTotals)); 79 | 80 | return invoices; 81 | } 82 | #endregion 83 | } 84 | 85 | #region Helper classes 86 | /// 87 | /// Represents a class to maintain invoice details. 88 | /// 89 | public class Invoice 90 | { 91 | #region Fields 92 | private List orders; 93 | private List order; 94 | private List orderTotal; 95 | #endregion 96 | 97 | #region Properties 98 | public List Orders 99 | { 100 | get { return orders; } 101 | set { orders = value; } 102 | } 103 | public List Order 104 | { 105 | get { return order; } 106 | set { order = value; } 107 | } 108 | public List OrderTotals 109 | { 110 | get { return orderTotal; } 111 | set { orderTotal = value; } 112 | } 113 | #endregion 114 | 115 | #region Constructor 116 | public Invoice(List orders, List order, List orderTotals) 117 | { 118 | Orders = orders; 119 | Order = order; 120 | OrderTotals = orderTotals; 121 | } 122 | #endregion 123 | } 124 | /// 125 | /// Represents a class to maintain orders details. 126 | /// 127 | public class Orders 128 | { 129 | #region Fields 130 | private string orderID; 131 | private string shipName; 132 | private string shipAddress; 133 | private string shipCity; 134 | private string shipPostalCode; 135 | private string shipCountry; 136 | private string customerID; 137 | private string address; 138 | private string postalCode; 139 | private string city; 140 | private string country; 141 | private string salesPerson; 142 | private string customersCompanyName; 143 | private string orderDate; 144 | private string requiredDate; 145 | private string shippedDate; 146 | private string shippersCompanyName; 147 | #endregion 148 | 149 | #region Properties 150 | public string ShipName 151 | { 152 | get { return shipName; } 153 | set { shipName = value; } 154 | } 155 | public string ShipAddress 156 | { 157 | get { return shipAddress; } 158 | set { shipAddress = value; } 159 | } 160 | public string ShipCity 161 | { 162 | get { return shipCity; } 163 | set { shipCity = value; } 164 | } 165 | public string ShipPostalCode 166 | { 167 | get { return shipPostalCode; } 168 | set { shipPostalCode = value; } 169 | } 170 | public string PostalCode 171 | { 172 | get { return postalCode; } 173 | set { postalCode = value; } 174 | } 175 | public string ShipCountry 176 | { 177 | get { return shipCountry; } 178 | set { shipCountry = value; } 179 | } 180 | public string CustomerID 181 | { 182 | get { return customerID; } 183 | set { customerID = value; } 184 | } 185 | public string Customers_CompanyName 186 | { 187 | get { return customersCompanyName; } 188 | set { customersCompanyName = value; } 189 | } 190 | public string Address 191 | { 192 | get { return address; } 193 | set { address = value; } 194 | } 195 | public string City 196 | { 197 | get { return city; } 198 | set { city = value; } 199 | } 200 | public string Country 201 | { 202 | get { return country; } 203 | set { country = value; } 204 | } 205 | public string Salesperson 206 | { 207 | get { return salesPerson; } 208 | set { salesPerson = value; } 209 | } 210 | public string OrderID 211 | { 212 | get { return orderID; } 213 | set { orderID = value; } 214 | } 215 | public string OrderDate 216 | { 217 | get { return orderDate; } 218 | set { orderDate = value; } 219 | } 220 | public string RequiredDate 221 | { 222 | get { return requiredDate; } 223 | set { requiredDate = value; } 224 | } 225 | public string ShippedDate 226 | { 227 | get { return shippedDate; } 228 | set { shippedDate = value; } 229 | } 230 | public string Shippers_CompanyName 231 | { 232 | get { return shippersCompanyName; } 233 | set { shippersCompanyName = value; } 234 | } 235 | #endregion 236 | 237 | #region Constructor 238 | public Orders(string orderID, string shipName, string shipAddress, string shipCity, 239 | string shipPostalCode, string shipCountry, string customerID, string address, 240 | string postalCode, string city, string country, string salesPerson, string customersCompanyName, 241 | string orderDate, string requiredDate, string shippedDate, string shippersCompanyName) 242 | { 243 | OrderID = orderID; 244 | ShipName = shipName; 245 | ShipAddress = shipAddress; 246 | ShipCity = shipCity; 247 | ShipPostalCode = shipPostalCode; 248 | ShipCountry = shipCountry; 249 | CustomerID = customerID; 250 | Address = address; 251 | PostalCode = postalCode; 252 | City = city; 253 | Country = country; 254 | Salesperson = salesPerson; 255 | Customers_CompanyName = customersCompanyName; 256 | OrderDate = orderDate; 257 | RequiredDate = requiredDate; 258 | ShippedDate = shippedDate; 259 | Shippers_CompanyName = shippersCompanyName; 260 | } 261 | #endregion 262 | } 263 | /// 264 | /// Represents a class to maintain order details. 265 | /// 266 | public class Order 267 | { 268 | #region Fields 269 | private string productID; 270 | private string productName; 271 | private string unitPrice; 272 | private string quantity; 273 | private string discount; 274 | private string extendedPrice; 275 | #endregion 276 | 277 | #region Properties 278 | public string ProductID 279 | { 280 | get { return productID; } 281 | set { productID = value; } 282 | } 283 | public string ProductName 284 | { 285 | get { return productName; } 286 | set { productName = value; } 287 | } 288 | public string UnitPrice 289 | { 290 | get { return unitPrice; } 291 | set { unitPrice = value; } 292 | } 293 | public string Quantity 294 | { 295 | get { return quantity; } 296 | set { quantity = value; } 297 | } 298 | public string Discount 299 | { 300 | get { return discount; } 301 | set { discount = value; } 302 | } 303 | public string ExtendedPrice 304 | { 305 | get { return extendedPrice; } 306 | set { extendedPrice = value; } 307 | } 308 | #endregion 309 | 310 | #region Constructor 311 | public Order(string productID, string productName, string unitPrice, string quantity, 312 | string discount, string extendedPrice) 313 | { 314 | ProductID = productID; 315 | ProductName = productName; 316 | UnitPrice = unitPrice; 317 | Quantity = quantity; 318 | Discount = discount; 319 | ExtendedPrice = extendedPrice; 320 | } 321 | #endregion 322 | } 323 | /// 324 | /// Represents a class to maintain order totals details. 325 | /// 326 | public class OrderTotals 327 | { 328 | #region Fields 329 | private string subTotal; 330 | private string freight; 331 | private string total; 332 | #endregion 333 | 334 | #region Properties 335 | public string Subtotal 336 | { 337 | get { return subTotal; } 338 | set { subTotal = value; } 339 | } 340 | public string Freight 341 | { 342 | get { return freight; } 343 | set { freight = value; } 344 | } 345 | public string Total 346 | { 347 | get { return total; } 348 | set { total = value; } 349 | } 350 | #endregion 351 | 352 | #region Constructor 353 | public OrderTotals(string subTotal, string freight, string total) 354 | { 355 | Subtotal = subTotal; 356 | Freight = freight; 357 | Total = total; 358 | } 359 | #endregion 360 | } 361 | #endregion 362 | } 363 | -------------------------------------------------------------------------------- /Start-each-record-on-new-page/Console-App-.NET-Core/Start-each-record-on-new-page/Start-each-record-on-new-page.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | Start_each_record_on_new_page 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Start-each-record-on-new-page/Console-App-.NET-Core/Start-each-record-on-new-page/Template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Start-each-record-on-new-page/Console-App-.NET-Core/Start-each-record-on-new-page/Template.docx -------------------------------------------------------------------------------- /Start-each-record-on-new-page/Images/Start-each-record-on-new-page-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Start-each-record-on-new-page/Images/Start-each-record-on-new-page-output.png -------------------------------------------------------------------------------- /Start-each-record-on-new-page/Images/Start-each-record-on-new-page-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionExamples/Mail-Merge-Examples/4e51cd82111426846338b4f9ff314bdc3e36eb01/Start-each-record-on-new-page/Images/Start-each-record-on-new-page-template.png -------------------------------------------------------------------------------- /Start-each-record-on-new-page/README.md: -------------------------------------------------------------------------------- 1 | # Start each record on a new page in C# 2 | 3 | This example illustrates how to generate each record in new page while executing group mail merge. 4 | 5 | # How to run the project 6 | 7 | 1. Download this project to a location in your disk. 8 | 9 | 2. Open the solution file using Visual Studio. 10 | 11 | 3. Rebuild the solution to install the required NuGet packages. 12 | 13 | 4. Run the application. 14 | 15 | # Screenshots 16 | 17 | By running this application, you will get the output Word document as follows. 18 | 19 |

20 | Start-each-record-on-new-page-output 21 |

22 | 23 | To start each record in new page, design the template document with the corresponding group start and group end present in the text body of the Word document as follows. 24 | 25 |

26 | Start-each-record-on-new-page-template 27 |

28 | 29 | Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/getting-started), where you will find other Word document processing operations along with features like [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge), [merge](https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents), and split documents, [find and replace](https://help.syncfusion.com/file-formats/docio/working-with-find-and-replace) text in the Word document, [protect](https://help.syncfusion.com/file-formats/docio/working-with-security) Word documents, and most importantly [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) and [image](https://help.syncfusion.com/file-formats/docio/word-to-image) conversions with code examples. --------------------------------------------------------------------------------