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 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Image_bytes_in_DataTable</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\image1.gif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

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

Original file line number Diff line number Diff line change
@@ -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;
}
}
/// <summary>
/// Gets the data to perform mail merge.
/// </summary>
/// <returns></returns>
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
}
}