Skip to content
Open
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 17
VisualStudioVersion = 17.14.37531.7 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply-Bullet-List-Formatting-To-Mail-Merge-Fields", "Apply-Bullet-List-Formatting-To-Mail-Merge-Fields\Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.csproj", "{FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B51C4AB2-0F01-4F3D-92E9-3EA8F7615BFC}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

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



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

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;

namespace Replacing_MergeField_With_Bullet_List
{
class Program
{
static void Main(string[] args)
{
// Loads existing Word document
using (WordDocument wordDocument = new WordDocument(Path.GetFullPath(@"Data/Template.docx")))
{
string[] fieldNames = { "ContactName", "CompanyName" };
string[] fieldValues = { "Nancy", "Syncfusion" };

// Uses mail merge events to perform formatting during runtime
wordDocument.MailMerge.MergeField += new MergeFieldEventHandler(ApplyListFormat);

// Performs mail merge
wordDocument.MailMerge.Execute(fieldNames, fieldValues);

// Saves Word document
wordDocument.Save(Path.GetFullPath(@"Output/Output.docx"));
}
}

/// <summary>
/// Applies the default bullet list formatting to the paragraph
/// that contains the current mail merge field.
/// </summary>
/// <param name="sender">The source of the mail merge event.</param>
/// <param name="args">
/// Contains data related to the current merge field, including
/// the merge field and its owner paragraph.
/// </param>
private static void ApplyListFormat(object sender, MergeFieldEventArgs args)
{
// Gets the owner paragraph of the current merge field
WParagraph paragraph = args.CurrentMergeField.OwnerParagraph;

// Applies bullet list style to the paragraph
paragraph.ListFormat.ApplyDefBulletStyle();
}

}
}
Loading