diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data.sln b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data.sln new file mode 100644 index 00000000..9324b861 --- /dev/null +++ b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.489 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail-merge-with-excel-data", "Mail-merge-with-excel-data\Mail-merge-with-excel-data.csproj", "{C564F7A0-276B-425F-A89B-6277D642B8FA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C564F7A0-276B-425F-A89B-6277D642B8FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C564F7A0-276B-425F-A89B-6277D642B8FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C564F7A0-276B-425F-A89B-6277D642B8FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C564F7A0-276B-425F-A89B-6277D642B8FA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C80BB448-A12B-4BF3-8001-D498599BA45C} + EndGlobalSection +EndGlobal diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/App.config b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/App.config new file mode 100644 index 00000000..5906e95b --- /dev/null +++ b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/App.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/CustomersReport.doc b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/CustomersReport.doc new file mode 100644 index 00000000..9257274b Binary files /dev/null and b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/CustomersReport.doc differ diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Mail-merge-with-excel-data.csproj b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Mail-merge-with-excel-data.csproj new file mode 100644 index 00000000..a2b8e924 --- /dev/null +++ b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Mail-merge-with-excel-data.csproj @@ -0,0 +1,111 @@ + + + + + Debug + AnyCPU + {C564F7A0-276B-425F-A89B-6277D642B8FA} + Exe + ExportExcelToWord + ExportExcelToWord + v4.8 + 512 + true + true + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Bcl.Cryptography.10.0.11\lib\net462\Microsoft.Bcl.Cryptography.dll + + + ..\packages\Syncfusion.Compression.Base.35.1.37\lib\net462\Syncfusion.Compression.Base.dll + + + ..\packages\Syncfusion.DocIO.WinForms.35.1.37\lib\net462\Syncfusion.DocIO.Base.dll + + + ..\packages\Syncfusion.Licensing.35.1.37\lib\net462\Syncfusion.Licensing.dll + + + ..\packages\Syncfusion.Markdown.35.1.37\lib\net462\Syncfusion.Markdown.dll + + + ..\packages\Syncfusion.OfficeChart.Base.35.1.37\lib\net462\Syncfusion.OfficeChart.Base.dll + + + ..\packages\Syncfusion.Telemetry.35.1.37\lib\net462\Syncfusion.Telemetry.dll + + + ..\packages\Syncfusion.XlsIO.WinForms.35.1.37\lib\net462\Syncfusion.XlsIO.Base.dll + + + + ..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll + + + + ..\packages\System.Formats.Asn1.10.0.11\lib\net462\System.Formats.Asn1.dll + + + ..\packages\System.Memory.4.6.3\lib\net462\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll + + + + ..\packages\System.Security.Cryptography.Xml.10.0.11\lib\net462\System.Security.Cryptography.Xml.dll + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/NorthwindDataTemplate.xls b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/NorthwindDataTemplate.xls new file mode 100644 index 00000000..3ea45c4d Binary files /dev/null and b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/NorthwindDataTemplate.xls differ diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Program.cs b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Program.cs new file mode 100644 index 00000000..af0a7920 --- /dev/null +++ b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Program.cs @@ -0,0 +1,48 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.XlsIO; +using System.Data; +using System.IO; +using System.Reflection; + +namespace MailMergeWithExcelData +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + //Instantiate the Excel application object + IApplication application = excelEngine.Excel; + + //Load an existing Excel file into IWorkbook + Assembly assembly = typeof(Program).GetTypeInfo().Assembly; + Stream excelStream = assembly.GetManifestResourceStream("ExportExcelToWord.NorthwindDataTemplate.xls"); + IWorkbook workbook = application.Workbooks.Open(excelStream, ExcelOpenType.Automatic); + + //Get the first worksheet in workbook into IWorksheet + IWorksheet worksheet = workbook.Worksheets[0]; + + //Initialize the DataTable + DataTable dataTable = new DataTable(); + + //Export the data in Excel worksheet into DataTable and assign table name + dataTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames); + dataTable.TableName = "Customers"; + + //Load an existing Word document into WordDocument + Stream wordStream = assembly.GetManifestResourceStream("ExportExcelToWord.CustomersReport.doc"); + WordDocument wordDocument = new WordDocument(wordStream); + + //Export the data in DataTable into Word document through MailMerge + wordDocument.MailMerge.Execute(dataTable); + + //Save the Word document and close the instance of WrodDocument + wordDocument.Save("Output.docx"); + wordDocument.Close(); + + System.Diagnostics.Process.Start("Output.docx"); + } + } + } +} \ No newline at end of file diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Properties/AssemblyInfo.cs b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..38360d93 --- /dev/null +++ b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApp1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleApp1")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c564f7a0-276b-425f-a89b-6277d642b8fa")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/packages.config b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/packages.config new file mode 100644 index 00000000..1654f498 --- /dev/null +++ b/Mail-Merge/Mail-merge-with-excel-data/Mail-merge-with-excel-data/packages.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file