diff --git a/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.sln b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.sln new file mode 100644 index 000000000..398f07cc4 --- /dev/null +++ b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35417.141 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-checkbox-using-IF-field", "Add-checkbox-using-IF-field\Add-checkbox-using-IF-field.csproj", "{CDB67E3F-6956-4FC5-8BC1-E4DB0A71C62E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CDB67E3F-6956-4FC5-8BC1-E4DB0A71C62E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CDB67E3F-6956-4FC5-8BC1-E4DB0A71C62E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CDB67E3F-6956-4FC5-8BC1-E4DB0A71C62E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CDB67E3F-6956-4FC5-8BC1-E4DB0A71C62E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.csproj b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.csproj new file mode 100644 index 000000000..a042038dd --- /dev/null +++ b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + Add_checkbox_using_IF_field + enable + enable + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Data/Template.docx b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Data/Template.docx new file mode 100644 index 000000000..aad17a4c1 Binary files /dev/null and b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Data/Template.docx differ diff --git a/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Output/.gitkeep b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Program.cs b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Program.cs new file mode 100644 index 000000000..fff5ab4a1 --- /dev/null +++ b/Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Program.cs @@ -0,0 +1,37 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) +{ + //Opens the template Word document. + using (WordDocument wordDocument = new WordDocument(inputStream, FormatType.Docx)) + { + // Set default values for the merge fields + string[] fieldNames = { "Name", "Email", "AgreeToTerms", "SubscribeNewsletter" }; + string[] fieldValues = { "Nancy", "nancy@example.com", "Yes", "No" }; + + // Execute mail merge to replace merge fields with actual values. + wordDocument.MailMerge.Execute(fieldNames, fieldValues); + + // Update any fields in the document to reflect the changes made during the mail merge. + wordDocument.UpdateDocumentFields(); + + // Set up font substitution settings for handling missing fonts. + wordDocument.FontSettings.SubstituteFont += FontSettings_SubstituteFont; + + // Save the modified document. + using (FileStream outputStream1 = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + wordDocument.Save(outputStream1, FormatType.Docx); + } + } +} + +/// +/// Handles font substitution when a required font is unavailable in the document. +/// +static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args) +{ + // Display the name of the original font that needs substitution + Console.WriteLine(args.OriginalFontName); +} \ No newline at end of file