From a5aeda9f924f6242c81a9d2e979b6913a801ecff Mon Sep 17 00:00:00 2001 From: VijayadharshiniMathiyalagan Date: Fri, 1 Nov 2024 13:58:33 +0530 Subject: [PATCH] Add Sample for use conditional fields to add check boxes during mail-merge --- .../Add-checkbox-using-IF-field.sln | 22 +++++++++++ .../Add-checkbox-using-IF-field.csproj | 27 +++++++++++++ .../Data/Template.docx | Bin 0 -> 11525 bytes .../Output/.gitkeep | 1 + .../Add-checkbox-using-IF-field/Program.cs | 37 ++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.sln create mode 100644 Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field.csproj create mode 100644 Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Data/Template.docx create mode 100644 Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Output/.gitkeep create mode 100644 Mail-Merge/Add-checkbox-using-IF-field/Add-checkbox-using-IF-field/Program.cs 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 00000000..398f07cc --- /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 00000000..a042038d --- /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 0000000000000000000000000000000000000000..aad17a4c1bba6a683d6bbe2dc7bde7cd564371aa GIT binary patch literal 11525 zcmeHtWmFtX*Y4mR+}(mZgKLl=!3hL+cMBez;4ruag1b9`puyeU-CYvo&as%*0-QL7WhuO`>nk*X{lJ+wI5RKbNmHXG<&o8!iY|%DS%DVHHG$^qlkn?00v7DEfqGH7but4wAqJ z9FDcy))lCv6>57rg*rIG7rLJ@km9Omf!?-K6nMt-PLuD<65a&r*J6bpcAq9XXRab1E_P^-$!y8We?Bc&Tc;H&x~`$}bYFUA@htuKm8i zB+dc>8d*xsE_;`?obgN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6MKgJzY4?wT(B#gcJYZOdqrXLx-qG~q+@9|D zmdFPZpNoFNgPMEz*T8%O$9pv?FtgZ$lRfC*bPhO&qv&X7@5Ewc=lDCXfa@;)o5KN1 zQADhq0=VuV_*ClQBmFIx9CwFm-6v>snwR8kLfykMEnH){N*MLmtCNXkMwL*n54|7y z-p3BR7Qf&!|77hf{|+k-0JIC7GLg?v3%8eq+!aMCB#h*>7zepKxPu(xE_yZsY>+is z#$i55e~C{^S6xYqSMFs{UCWLd(`mFVg)Ct^7=0xb1lfj)~02S&u%|% zR$9`!_%KA}?wzUxTn?VZTZL}qGi7Y^*OJj!md9$s%AO@yX9Z(8OFmz;c5X=CD5$)F zGi0oJ%%E$4Cy^K%PWoWyB&GYZ!Lsw8{PJzQi;<(=9>#POTGdm-8 zULXndH`eogQo67Is;iE#4Dp=7>^A^rKeWHIpMkyoZ<^}A+y~w^@RhDSC=bpcwosm< zDxFMOh{69Bu`q|<2v*>)Ss5Q%u&=R_y9p(?G)ua7 zR^Gzb+>funW?zlJHB)!TiK~>sGjm8eW!vF?xPsOVxWtR?Nd^T*4z@`5v*3kScc^tE z)G@ix<7$H7gHxM|CooRaAI!&JaxsMQcImt-QT%i-%6f{8o4MbXJXRB3CBu>sc?qF!Pb zeK|(@3*mQo@NS=R5%MPsG_-Q~R_+(~a2k)>US^Kaz-H<~*Rr3V&>FCf|BoV|U*Z2u+5ZFs z09@eU?EjR&|CQ3OY22T*tWo|SN!?#b{F-3;Ndg;O(e(Rb{+@3775-~T`6t{EoLBw> z{(l3^zk+{tMSp_L$o~ZY;+XzQ;aA`4CxtnRKPmjf)A|+vPjmYd4FJGU0|5VFe1C=i jQ(gWY9!T>y_@ByCQ5FWw9=}ymA^|$U3YMAvw_pDUxhhqu literal 0 HcmV?d00001 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 00000000..5f282702 --- /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 00000000..fff5ab4a --- /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