-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES-264021- Add the sample Generate-Documents-for-each-record #382
Merged
MohanaselvamJothi
merged 2 commits into
main
from
ES-264021-Generate-Documents-for-each-record
Mar 28, 2025
+121
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Mail-Merge/Generate-Documents-for-each-record/.NET/Generate-Documents-for-each-record.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") = "Generate-Documents-for-each-record", "Generate-Documents-for-each-record\Generate-Documents-for-each-record.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4} | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+12.3 KB
...rate-Documents-for-each-record/.NET/Generate-Documents-for-each-record/Data/Template.docx
Binary file not shown.
22 changes: 22 additions & 0 deletions
22
...-record/.NET/Generate-Documents-for-each-record/Generate-Documents-for-each-record.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Generate_Documents_for_each_record</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Data\Template.docx"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Output\.gitkeep"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
1 change: 1 addition & 0 deletions
1
...enerate-Documents-for-each-record/.NET/Generate-Documents-for-each-record/Output/.gitkeep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
73 changes: 73 additions & 0 deletions
73
...rge/Generate-Documents-for-each-record/.NET/Generate-Documents-for-each-record/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIO.DLS; | ||
using System.Data; | ||
using System.IO; | ||
|
||
namespace Generate_Documents_for_each_record | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
//Open the file as Stream. | ||
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open)) | ||
{ | ||
//Load file stream into Word document. | ||
using (WordDocument template = new WordDocument(fileStream, FormatType.Docx)) | ||
{ | ||
//Get the data for mail merge. | ||
DataTable table = GetDataTable(); | ||
//Iterate to the each row and generate mail merged document for each rows. | ||
for (int i = 0; i < table.Rows.Count; i++) | ||
{ | ||
//Clones the template document for creating new document for each record in the data source | ||
WordDocument document = template.Clone(); | ||
//Executes mail merge using the data row. | ||
document.MailMerge.Execute(table.Rows[i]); | ||
|
||
//Create a file stream. | ||
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/" + "Record_" + (i + 1) + ".docx"), FileMode.Create, FileAccess.ReadWrite)) | ||
{ | ||
//Save the Word document to the file stream. | ||
document.Save(outputFileStream, FormatType.Docx); | ||
} | ||
//Releases the resources occupied by WordDocument instance | ||
document.Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
/// <summary> | ||
/// Get the data for mail merge. | ||
/// </summary> | ||
/// <returns></returns> | ||
static DataTable GetDataTable() | ||
{ | ||
DataTable table = new DataTable(); | ||
|
||
//Defining columns | ||
table.Columns.Add("Name"); | ||
table.Columns.Add("Street"); | ||
table.Columns.Add("City"); | ||
table.Columns.Add("ProjectNo"); | ||
|
||
//Set values | ||
DataRow row; | ||
row = table.NewRow(); | ||
row["Name"] = "Andreas Waning"; | ||
row["Street"] = "Middelwegg 2"; | ||
row["City"] = "Vreden"; | ||
row["ProjectNo"] = "4711"; | ||
table.Rows.Add(row); | ||
|
||
row = table.NewRow(); | ||
row["Name"] = "Mike Korf"; | ||
row["Street"] = "teststreet"; | ||
row["City"] = "TestCity"; | ||
row["ProjectNo"] = "4711"; | ||
table.Rows.Add(row); | ||
|
||
return table; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside the loop, clone the original document and then do mail merge
https://github.com/SyncfusionExamples/Mail-Merge-Examples/blob/master/Create-and-send-email-messages/Console-App-.NET-Core/Create-and-send-email-messages/Program.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed the feedback