diff --git a/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable.sln b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable.sln new file mode 100644 index 000000000..1d5725867 --- /dev/null +++ b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31911.196 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Image-bytes-in-DataTable", "Image-bytes-in-DataTable\Image-bytes-in-DataTable.csproj", "{D3AF529E-DB54-4294-A876-DD42E1E472D0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {58137FF9-5AE1-4514-9929-3A8A7DA1DFEB} + EndGlobalSection +EndGlobal diff --git a/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Data/Template.docx b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Data/Template.docx new file mode 100644 index 000000000..896ef7aa2 Binary files /dev/null and b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Data/Template.docx differ diff --git a/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Data/image1.gif b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Data/image1.gif new file mode 100644 index 000000000..21ee3adf8 Binary files /dev/null and b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Data/image1.gif differ diff --git a/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Image-bytes-in-DataTable.csproj b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Image-bytes-in-DataTable.csproj new file mode 100644 index 000000000..879ecf8c5 --- /dev/null +++ b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Image-bytes-in-DataTable.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + Image_bytes_in_DataTable + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Output/.gitkeep b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Program.cs b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Program.cs new file mode 100644 index 000000000..fbd868db2 --- /dev/null +++ b/Mail-Merge/Image-bytes-in-DataTable/.NET/Image-bytes-in-DataTable/Program.cs @@ -0,0 +1,76 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.Drawing; +using System.Collections.Generic; +using System.Data; +using System.IO; + +namespace Modify_font_during_mail_merge +{ + class Program + { + static void Main(string[] args) + { + Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NMaF5cXmBCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdmWX1cdnRRQ2NcUkZwXUo="); + using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) + { + //Opens the template document. + using (WordDocument document = new WordDocument(fileStream, FormatType.Docx)) + { + //Gets the DataTable + DataTable dataTable = GetDataTable(); + //Triggers the event + document.MailMerge.MergeImageField += MergeField_ProductImage; + //Performs mail merge + document.MailMerge.Execute(dataTable); + //Creates file stream. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputStream, FormatType.Docx); + } + } + } + } + + #region Helper methods + private static void MergeField_ProductImage(object sender, MergeImageFieldEventArgs args) + { + if (args.FieldName == "Photo") + { + args.Picture.Height = 85; + args.Picture.Width = 140; + } + } + /// + /// Gets the data to perform mail merge. + /// + /// + private static DataTable GetDataTable() + { + //Creates new DataTable instance + DataTable table = new DataTable(); + //Add columns in DataTable + table.Columns.Add("Photo", typeof(byte[])); + table.Columns.Add("ProductName"); + table.Columns.Add("ProductNumber"); + table.Columns.Add("Size"); + table.Columns.Add("Weight"); + table.Columns.Add("Price"); + + //Add record in new DataRow + DataRow row = table.NewRow(); + byte[] imageBytes = File.ReadAllBytes(@"Data/image1.gif"); + row["Photo"] = imageBytes; + row["ProductName"] = "Mountain-200"; + row["ProductNumber"] = "BK-M68B-38"; + row["Size"] = "38"; + row["Weight"] = "25"; + row["Price"] = "$2,294.99"; + table.Rows.Add(row); + + return table; + } + #endregion + } +}