Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.37216.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generate-multiple-Word-documents", "Generate-multiple-Word-documents\Generate-multiple-Word-documents.csproj", "{4CE62E51-B973-4054-B932-9037D1A31029}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4CE62E51-B973-4054-B932-9037D1A31029}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CE62E51-B973-4054-B932-9037D1A31029}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CE62E51-B973-4054-B932-9037D1A31029}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CE62E51-B973-4054-B932-9037D1A31029}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F50F5E41-86EF-430C-8B45-E147E4022E74}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Generate_multiple_Word_documents</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
<PackageReference Include="System.Data.OleDb" Version="10.0.7" />
</ItemGroup>

<ItemGroup>
<None Update="Data\CustomerDetails.mdb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\LetterTemplate.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.Data;
using System.Data.OleDb;

namespace Generate_Multiple_Word_Documents
{
class Program
{
public static void Main(string[] args)
{
//Creates new Word document instance for Word processing
using (WordDocument template = new WordDocument())
{
//Opens the Word template document
template.Open(Path.GetFullPath("Data/LetterTemplate.docx"), FormatType.Docx);
//Gets the recipient details as DataTable
DataTable recipients = GetRecipients();
//Creates folder for saving generated documents
if (!Directory.Exists(Path.GetFullPath(@"../../../Output/")))
Directory.CreateDirectory(Path.GetFullPath(@"../../../Output/"));
foreach (DataRow dataRow in recipients.Rows)
{
//Clones the template document for creating new document for each record in the data source
WordDocument document = template.Clone();
//Performs the mail merge
document.MailMerge.Execute(dataRow);
//Save the file in the given path
document.Save(Path.GetFullPath(@"../../../Output/Letter_" + dataRow.ItemArray[2].ToString() + ".docx"), FormatType.Docx);
//Releases the resources occupied by WordDocument instance
document.Dispose();
}
}
}

#region Helper methods
/// <summary>
/// Gets the data to perform mail merge.
/// </summary>
/// <returns></returns>
private static DataTable GetRecipients()
{
//Creates new DataTable instance
DataTable table = new DataTable();
//Loads the database
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetFullPath("Data/CustomerDetails.mdb"));
//Opens the database connection
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from Customers", conn);
//Gets the data from the database
adapter.Fill(table);
//Releases the memory occupied by database connection
adapter.Dispose();
conn.Close();
return table;
}
#endregion
}
}
Loading