Skip to content

Commit 4d887d8

Browse files
committed
Add XML commants
1 parent a0912c2 commit 4d887d8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • Mail-Merge/Apply-custom-formatting-mailmerge-fields/.NET/Apply-custom-formatting-mailmerge-fields

Mail-Merge/Apply-custom-formatting-mailmerge-fields/.NET/Apply-custom-formatting-mailmerge-fields/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static Dictionary<WParagraph, List<KeyValuePair<int, string>>> paratoModi
1111
= new Dictionary<WParagraph, List<KeyValuePair<int, string>>>();
1212
public static void Main(string[] args)
1313
{
14+
// Load the existing word document
1415
WordDocument document = new WordDocument(Path.GetFullPath(@"Data\Template.docx"));
1516
// Enable separate page for each invoice
1617
document.MailMerge.StartAtNewPage = true;
@@ -20,7 +21,9 @@ public static void Main(string[] args)
2021
// Update the merge field results with formatted values.
2122
UpdateMergeFieldResult(true);
2223
UpdateMergeFieldResult(false);
24+
// Save the Word document.
2325
document.Save(Path.GetFullPath(@"../../../Output/Output.docx"));
26+
// Close the document
2427
document.Close();
2528

2629
}
@@ -76,7 +79,7 @@ public static void UpdateMergeFieldResult(bool numberType)
7679
{
7780
// Get the merge field result paragraph
7881
WParagraph mergeFieldParagraph = dictionaryItem.Key;
79-
// The list of (index, fieldVales) pairs for this paragraph.
82+
// The list of (index, fieldValues) pairs for this paragraph.
8083
var fieldList = dictionaryItem.Value;
8184
for (int i = 0; i <= fieldList.Count - 1; i++)
8285
{
@@ -95,13 +98,13 @@ public static void UpdateMergeFieldResult(bool numberType)
9598
// Check if the Number field value
9699
if (numberType)
97100
{
98-
// Format number: 1,234.567 → Indian or US style
101+
// Format number: 1,234.56
99102
field.FieldCode = $"IF 1 = 1 \"{fieldValue}\" \" \" \\# \"#,##0.00";
100103
}
101104
// Update the Date field value
102105
else
103106
{
104-
// Format date: dd/MM/yyyy
107+
// Format date: dd/MMM/yyyy
105108
field.FieldCode = $"IF 1 = 1 \"{fieldValue}\" \" \" \\@ \"dd/MMM/yyyy\" ";
106109
}
107110
// Update the field and unlink

0 commit comments

Comments
 (0)