-|
ASP.NET MVC5
|
diff --git a/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Convert-PowerPoint-to-PDF-in-Blazor.md b/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Convert-PowerPoint-to-PDF-in-Blazor.md
index c51b22f712..bbf0ea563c 100644
--- a/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Convert-PowerPoint-to-PDF-in-Blazor.md
+++ b/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Convert-PowerPoint-to-PDF-in-Blazor.md
@@ -8,7 +8,7 @@ documentation: UG
# Convert PowerPoint to PDF in Blazor
-Syncfusion® PowerPoint is a [.NET Core PowerPoint library](https://www.syncfusion.com/document-sdk/net-powerpoint-library) used to create, read, edit and convert PowerPoint presentation programmatically without **Microsoft PowerPoint** or interop dependencies. Using this library, you can convert a PowerPoint Presentation to PDF in Blazor.
+Syncfusion® PowerPoint is a [.NET Core PowerPoint library](https://www.syncfusion.com/document-sdk/net-powerpoint-library) used to create, read, edit and convert PowerPoint presentation programmatically without **Microsoft PowerPoint** or interop dependencies. Using this library, you can **convert a PowerPoint Presentation to PDF in Blazor**.
## Blazor Web App Server Application
@@ -34,9 +34,7 @@ Step 1: Create a new C# Blazor Web app project.

-Step 2: Install the `Syncfusion.PresentationRenderer.Net.Core` NuGet package.
-
-To convert a **PowerPoint presentation to PDF in a Web App Server**, install the [Syncfusion.PresentationRenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.PresentationRenderer.Net.Core) NuGet package as reference to the project from [NuGet.org](https://www.nuget.org/).
+Step 2: To convert a **PowerPoint presentation to PDF in a Blazor Web App Server**, install the [Syncfusion.PresentationRenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.PresentationRenderer.Net.Core) NuGet package from [NuGet.org](https://www.nuget.org/).

diff --git a/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Fallback-Fonts-in-PPTXtoPDF-Conversion.md b/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Fallback-Fonts-in-PPTXtoPDF-Conversion.md
index 993badc158..cf2a926fe3 100644
--- a/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Fallback-Fonts-in-PPTXtoPDF-Conversion.md
+++ b/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Fallback-Fonts-in-PPTXtoPDF-Conversion.md
@@ -188,36 +188,21 @@ The following code example demonstrates how a user can add fallback fonts for Sy
{% tabs %}
{% highlight C# tabtitle="C# [Cross-platform]" %}
-//Load the PowerPoint presentation into stream.
-using (FileStream fileStreamInput = new FileStream("Template.pptx", FileMode.Open, FileAccess.Read))
-{
- //Open the existing PowerPoint presentation with loaded stream.
- using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
- {
- //Adds fallback font for basic symbols like bullet characters.
- pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings");
- //Adds fallback font for mathematics symbols.
- pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS");
- //Adds fallback font for emojis.
- pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS");
- //Create the MemoryStream to save the converted PDF.
- using (MemoryStream pdfStream = new MemoryStream())
- {
- //Convert the PowerPoint document to PDF document.
- using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
- {
- //Save the converted PDF document to MemoryStream.
- pdfDocument.Save(pdfStream);
- pdfStream.Position = 0;
- }
- //Create the output PDF file stream.
- using (FileStream fileStreamOutput = File.Create("Output.pdf"))
- {
- //Copy the converted PDF stream into created output PDF stream.
- pdfStream.CopyTo(fileStreamOutput);
- }
- }
- }
+//Open the existing PowerPoint presentation.
+using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx"))
+ {
+ //Adds fallback font for basic symbols like bullet characters.
+ pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings");
+ //Adds fallback font for mathematics symbols.
+ pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS");
+ //Adds fallback font for emojis.
+ pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS");
+ //Convert the PowerPoint document to PDF document.
+ using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
+ {
+ //Save the PDF document to the file system.
+ pdfDocument.Save(@"../../../Output/PPTXToPDF.pdf");
+ }
}
{% endhighlight %}
diff --git a/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Font-Substitution-in-PPTXtoPDF-Conversion.md b/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Font-Substitution-in-PPTXtoPDF-Conversion.md
index 60806937e4..a1791658bd 100644
--- a/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Font-Substitution-in-PPTXtoPDF-Conversion.md
+++ b/Document-Processing/PowerPoint/Conversions/PowerPoint-To-PDF/NET/Font-Substitution-in-PPTXtoPDF-Conversion.md
@@ -138,7 +138,7 @@ using (IPresentation pptxDoc = Presentation.Open("Sample.pptx"))
///
/// FontSettings type of the Presentation in which the specified font stream is used but unavailable in production environment.
/// Retrieves the unavailable font name and receives the substitute font stream for conversion.
-private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
+private static void SubstituteFont(object sender, SubstituteFontEventArgs args)
{
if (args.OriginalFontName == "Arial" && args.FontStyle == FontStyle.Bold)
args.AlternateFontStream = new FileStream("cambriab.ttf", FileMode.Open);
diff --git a/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-Animation.md b/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-Animation.md
index 821356dfff..b51a0e02cb 100644
--- a/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-Animation.md
+++ b/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-Animation.md
@@ -31,7 +31,7 @@ IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add normal shape to slide
-IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300);
+IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 100, 100, 300, 300);
//Access the animation sequence to create effects
ISequence sequence = slide.Timeline.MainSequence;
//Add bounce effect to the shape
@@ -47,7 +47,7 @@ using (IPresentation pptxDoc = Presentation.Create())
//Add a blank slide to Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add normal shape to slide
- IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300);
+ IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 100, 100, 300, 300);
//Access the animation sequence to create effects
ISequence sequence = slide.Timeline.MainSequence;
//Add bounce effect to the shape
@@ -63,7 +63,7 @@ Using pptxDoc As IPresentation = Presentation.Create()
'Add a blank slide to Presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add normal shape to slide
- Dim cubeShape As IShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300)
+ Dim cubeShape As IShape = slide.Shapes.AddShape(AutoShapeType.Cube, 100, 100, 300, 300)
'Access the animation sequence to create effects
Dim sequence As ISequence = slide.Timeline.MainSequence
'Add bounce effect to the shape
@@ -89,9 +89,9 @@ IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add normal shape to slide
-IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300);
-//Add a shape to act as button
-IShape buttonShape = slide.Shapes.AddShape(AutoShapeType.Oval, 100,100,50,50);
+IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 200, 100, 300, 300);
+//Add a shape to act as button.
+IShape buttonShape = slide.Shapes.AddShape(AutoShapeType.Oval, 130, 75, 50, 50);
//Create the interactive sequence to make the animation effects interactive by triggering with button click
ISequence interactiveSequence = slide.Timeline.InteractiveSequences.Add(buttonShape);
//Add Fly effect with top subtype to animate the shape as fly from top
@@ -107,9 +107,9 @@ using (IPresentation pptxDoc = Presentation.Create())
//Add a blank slide to Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add normal shape to slide
- IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300);
- //Add a shape to act as button
- IShape buttonShape = slide.Shapes.AddShape(AutoShapeType.Oval, 100,100,50,50);
+ IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 200, 100, 300, 300);
+ //Add a shape to act as button.
+ IShape buttonShape = slide.Shapes.AddShape(AutoShapeType.Oval, 130, 75, 50, 50);
//Create the interactive sequence to make the animation effects interactive by triggering with button click
ISequence interactiveSequence = slide.Timeline.InteractiveSequences.Add(buttonShape);
//Add Fly effect with top subtype to animate the shape as fly from top
@@ -125,9 +125,9 @@ Using pptxDoc As IPresentation = Presentation.Create()
'Add a blank slide to Presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add normal shape to slide
- Dim cubeShape As IShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300)
+ Dim cubeShape As IShape = slide.Shapes.AddShape(AutoShapeType.Cube, 200, 100, 300, 300)
'Add a shape to act as button
- Dim buttonShape As IShape = slide.Shapes.AddShape(AutoShapeType.Oval, 100, 100, 50, 50)
+ Dim buttonShape As IShape = slide.Shapes.AddShape(AutoShapeType.Oval, 130, 75, 50, 50)
'Create the interactive sequence to make the animation effects interactive by triggering with button click
Dim interactiveSequence As ISequence = slide.Timeline.InteractiveSequences.Add(buttonShape)
'Add Fly effect with top subtype to animate the shape as fly from top
@@ -212,7 +212,7 @@ IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add normal shape to slide
-IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300);
+IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 100, 100, 300, 300);
//Access the animation sequence to create effects
ISequence sequence = slide.Timeline.MainSequence;
//Add random bars effect to the shape
@@ -230,7 +230,7 @@ using (IPresentation pptxDoc = Presentation.Create())
//Add a blank slide to Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add normal shape to slide
- IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300);
+ IShape cubeShape = slide.Shapes.AddShape(AutoShapeType.Cube, 100, 100, 300, 300);
//Access the animation sequence to create effects
ISequence sequence = slide.Timeline.MainSequence;
//Add random bars effect to the shape
@@ -248,7 +248,7 @@ Using pptxDoc As IPresentation = Presentation.Create()
'Add a blank slide to Presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add normal shape to slide
- Dim cubeShape As IShape = slide.Shapes.AddShape(AutoShapeType.Cube, 50, 200, 300, 300)
+ Dim cubeShape As IShape = slide.Shapes.AddShape(AutoShapeType.Cube, 100, 100, 300, 300)
'Access the animation sequence to create effects
Dim sequence As ISequence = slide.Timeline.MainSequence
'Add random bars effect to the shape
diff --git a/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-shapes.md b/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-shapes.md
index db61cc0c8b..b344582f9e 100644
--- a/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-shapes.md
+++ b/Document-Processing/PowerPoint/PowerPoint-Library/NET/Working-with-shapes.md
@@ -149,7 +149,7 @@ IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Gets the first slide of the Presentation
ISlide slide = pptxDoc.Slides[0];
//Gets the first shape of the slide
-IShape shape = slide.Shapes[0];
+IShape shape = slide.Shapes[0] as IShape;
//Sets the shape name
shape.ShapeName = "Shape1";
//Retrieves the line format of the shape
@@ -178,7 +178,7 @@ IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Gets the first slide of the Presentation
ISlide slide = pptxDoc.Slides[0];
//Gets the first shape of the slide
-IShape shape = slide.Shapes[0];
+IShape shape = slide.Shapes[0] as IShape;
//Sets the shape name
shape.ShapeName = "Shape1";
//Retrieves the line format of the shape
diff --git a/Document-Processing/Word/Word-Library/NET/Word-document/Compare-Word-documents.md b/Document-Processing/Word/Word-Library/NET/Word-document/Compare-Word-documents.md
index ea797ad22a..f2ef60b190 100644
--- a/Document-Processing/Word/Word-Library/NET/Word-document/Compare-Word-documents.md
+++ b/Document-Processing/Word/Word-Library/NET/Word-document/Compare-Word-documents.md
@@ -37,12 +37,15 @@ N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-plat
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Compare-Word-documents/Compare-two-Word-documents/.NET/Compare-Word-documents/Program.cs" %}
-//Load the original document.
+using Syncfusion.DocIO;
+using Syncfusion.DocIO.DLS;
+
+// Load the original document.
using (FileStream originalDocumentStreamPath = new FileStream("Data/OriginalDocument.docx", FileMode.Open, FileAccess.Read))
{
using (WordDocument originalDocument = new WordDocument(originalDocumentStreamPath, FormatType.Docx))
{
- //Load the revised document.
+ // Load the revised document.
using (FileStream revisedDocumentStreamPath = new FileStream("Data/RevisedDocument.docx", FileMode.Open, FileAccess.Read))
{
using (WordDocument revisedDocument = new WordDocument(revisedDocumentStreamPath, FormatType.Docx))
@@ -50,38 +53,48 @@ using (FileStream originalDocumentStreamPath = new FileStream("Data/OriginalDocu
// Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument);
- //Save the Word document to MemoryStream
- MemoryStream stream = new MemoryStream();
- originalDocument.Save(stream, FormatType.Docx);
+ // Save the Word document to MemoryStream.
+ using (MemoryStream stream = new MemoryStream())
+ {
+ originalDocument.Save(stream, FormatType.Docx);
+ // Save the stream to a file.
+ File.WriteAllBytes("Result.docx", stream.ToArray());
+ }
}
- }
- }
+ }
+ }
}
{% endhighlight %}
{% highlight c# tabtitle="C# [Windows-specific]" %}
-//Load the original document.
+using Syncfusion.DocIO;
+using Syncfusion.DocIO.DLS;
+
+// Load the original document.
using (WordDocument originalDocument = new WordDocument("Data/OriginalDocument.docx", FormatType.Docx))
{
- //Load the revised document.
+ // Load the revised document.
using (WordDocument revisedDocument = new WordDocument("Data/RevisedDocument.docx", FormatType.Docx))
- {
+ {
// Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument);
- //Save the Word document.
- originalDocument.Save("Result.docx");
+ // Save the Word document.
+ originalDocument.Save("Result.docx");
}
}
{% endhighlight %}
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
+Imports Syncfusion.DocIO
+Imports Syncfusion.DocIO.DLS
+
' Load the original document.
Using originalDocument As New WordDocument("Data/OriginalDocument.docx", FormatType.Docx)
' Load the revised document.
Using revisedDocument As New WordDocument("Data/RevisedDocument.docx", FormatType.Docx)
- ' Compare the original document and revised documents.
+ ' Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument)
' Save the Word document.
originalDocument.Save("Result.docx")
@@ -97,61 +110,74 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
## Set Author and Date
-Compare the two Word documents by setting the author and date for revisions to identify the changes. In DocIO, the default setting for the "author" field is "Author", and the default setting for the "dateTime" field is the current time.
+Compare the two Word documents by setting the author and date for revisions to identify the changes. In DocIO, the default author is "Author" and the default date/time is the current time. The following sample uses an overload of the [`Compare`](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html) method that accepts an author and date.
The following code example shows how to set the author and date for revision while comparing two Word documents.
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Compare-Word-documents/Set-author-and-date/.NET/Program.cs" %}
-//Load the original document.
+using Syncfusion.DocIO;
+using Syncfusion.DocIO.DLS;
+
+// Load the original document.
using (FileStream originalDocumentStreamPath = new FileStream("Data/OriginalDocument.docx", FileMode.Open, FileAccess.Read))
{
using (WordDocument originalDocument = new WordDocument(originalDocumentStreamPath, FormatType.Docx))
{
- //Load the revised document.
+ // Load the revised document.
using (FileStream revisedDocumentStreamPath = new FileStream("Data/RevisedDocument.docx", FileMode.Open, FileAccess.Read))
{
using (WordDocument revisedDocument = new WordDocument(revisedDocumentStreamPath, FormatType.Docx))
{
// Compare the original and revised Word documents.
- originalDocument.Compare(revisedDocument,"Nancy Davolio", DateTime.Now.AddDays(-1));
+ originalDocument.Compare(revisedDocument, "Nancy Davolio", DateTime.Now.AddDays(-1));
- //Save the Word document to MemoryStream
- MemoryStream stream = new MemoryStream();
- originalDocument.Save(stream, FormatType.Docx);
+ // Save the Word document to MemoryStream.
+ using (MemoryStream stream = new MemoryStream())
+ {
+ originalDocument.Save(stream, FormatType.Docx);
+ // Save the stream to a file.
+ File.WriteAllBytes("Result.docx", stream.ToArray());
+ }
}
- }
- }
+ }
+ }
}
{% endhighlight %}
{% highlight c# tabtitle="C# [Windows-specific]" %}
-//Load the original document.
+using Syncfusion.DocIO;
+using Syncfusion.DocIO.DLS;
+
+// Load the original document.
using (WordDocument originalDocument = new WordDocument("Data/OriginalDocument.docx", FormatType.Docx))
{
- //Load the revised document.
+ // Load the revised document.
using (WordDocument revisedDocument = new WordDocument("Data/RevisedDocument.docx", FormatType.Docx))
- {
- // Compare the original document and revised documents.
- originalDocument.Compare(revisedDocument,"Nancy Davolio", DateTime.Now.AddDays(-1));
- //Save the Word document.
- originalDocument.Save("Result.docx");
+ {
+ // Compare the original and revised Word documents.
+ originalDocument.Compare(revisedDocument, "Nancy Davolio", DateTime.Now.AddDays(-1));
+ // Save the Word document.
+ originalDocument.Save("Result.docx");
}
}
{% endhighlight %}
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
-' Open the original Word document.
-Using originalDocument As New WordDocument(originalFilePath, FormatType.Docx)
- ' Open the revised Word document.
- Using revisedDocument As New WordDocument(revisedFilePath, FormatType.Docx)
- ' Compare the original document with the revised document.
+Imports Syncfusion.DocIO
+Imports Syncfusion.DocIO.DLS
+
+' Load the original document.
+Using originalDocument As New WordDocument("Data/OriginalDocument.docx", FormatType.Docx)
+ ' Load the revised document.
+ Using revisedDocument As New WordDocument("Data/RevisedDocument.docx", FormatType.Docx)
+ ' Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument, "Nancy Davolio", DateTime.Now.AddDays(-1))
' Save the Word document.
- originalDocument.Save(resultFilePath)
+ originalDocument.Save("Result.docx")
End Using
End Using
@@ -176,25 +202,30 @@ The following code example illustrates how to compare two Word documents by igno
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Compare-Word-documents/Ignore-format-changes/.NET/Ignore-format-changes/Program.cs" %}
-//Load the original document
-using (FileStream originalDocumentStreamPath = new FileStream("OriginalDocument.docx", FileMode.Open, FileAccess.Read))
+using Syncfusion.DocIO;
+using Syncfusion.DocIO.DLS;
+
+// Load the original document.
+using (FileStream originalDocumentStreamPath = new FileStream("Data/OriginalDocument.docx", FileMode.Open, FileAccess.Read))
{
using (WordDocument originalDocument = new WordDocument(originalDocumentStreamPath, FormatType.Docx))
{
- //Load the revised document
- using (FileStream revisedDocumentStreamPath = new FileStream("RevisedDocument.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ // Load the revised document.
+ using (FileStream revisedDocumentStreamPath = new FileStream("Data/RevisedDocument.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
- using (WordDocument revisedDocument = new WordDocument(revisedDocumentStreamPath, FormatType.Automatic))
+ using (WordDocument revisedDocument = new WordDocument(revisedDocumentStreamPath, FormatType.Docx))
{
- //Set the Comparison option to detect format changes, whether to detect format changes while comparing two Word documents.
+ // Set whether to detect format changes while comparing two Word documents.
ComparisonOptions compareOptions = new ComparisonOptions();
compareOptions.DetectFormatChanges = false;
- //Compare the original document with the revised document
+ // Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument, "Syncfusion", DateTime.Now, compareOptions);
- //Save the Word document to MemoryStream
+ // Save the Word document to MemoryStream.
using (MemoryStream stream = new MemoryStream())
{
originalDocument.Save(stream, FormatType.Docx);
+ // Save the stream to a file.
+ File.WriteAllBytes("Result.docx", stream.ToArray());
}
}
}
@@ -204,36 +235,42 @@ using (FileStream originalDocumentStreamPath = new FileStream("OriginalDocument.
{% endhighlight %}
{% highlight c# tabtitle="C# [Windows-specific]" %}
-//Load the original document
-using (WordDocument originalDocument = new WordDocument("OriginalDocument.docx"))
+using Syncfusion.DocIO;
+using Syncfusion.DocIO.DLS;
+
+// Load the original document.
+using (WordDocument originalDocument = new WordDocument("Data/OriginalDocument.docx", FormatType.Docx))
{
- //Load the revised document
- using (WordDocument revisedDocument = new WordDocument("RevisedDocument.docx"))
+ // Load the revised document.
+ using (WordDocument revisedDocument = new WordDocument("Data/RevisedDocument.docx", FormatType.Docx))
{
- //Set the Comparison option detect format changes, whether to detect format changes while comparing two Word documents.
+ // Set whether to detect format changes while comparing two Word documents.
ComparisonOptions compareOptions = new ComparisonOptions();
compareOptions.DetectFormatChanges = false;
- //Compare the original document with the revised document
+ // Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument, "Syncfusion", DateTime.Now, compareOptions);
- //Save the Word document.
- originalDocument.Save(output);
- }
-}
+ // Save the Word document.
+ originalDocument.Save("Result.docx");
+ }
+}
{% endhighlight %}
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
-'Load the original document
-Using originalDocument As New WordDocument("OriginalDocument.docx")
- 'Load the revised document
- Using revisedDocument As New WordDocument("RevisedDocument.docx")
- 'Set the Comparison option to detect format changes
+Imports Syncfusion.DocIO
+Imports Syncfusion.DocIO.DLS
+
+' Load the original document.
+Using originalDocument As New WordDocument("Data/OriginalDocument.docx", FormatType.Docx)
+ ' Load the revised document.
+ Using revisedDocument As New WordDocument("Data/RevisedDocument.docx", FormatType.Docx)
+ ' Set whether to detect format changes while comparing two Word documents.
Dim compareOptions As New ComparisonOptions()
compareOptions.DetectFormatChanges = False
- 'Compare the original document with the revised document
+ ' Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument, "Syncfusion", DateTime.Now, compareOptions)
- 'Save the Word document
- originalDocument.Save(output)
+ ' Save the Word document.
+ originalDocument.Save("Result.docx")
End Using
End Using
diff --git a/Document-Processing/Word/Word-Library/NET/Word-document/Iterating-Word-document-elements.md b/Document-Processing/Word/Word-Library/NET/Word-document/Iterating-Word-document-elements.md
index c3f21a3288..2671a6625c 100644
--- a/Document-Processing/Word/Word-Library/NET/Word-document/Iterating-Word-document-elements.md
+++ b/Document-Processing/Word/Word-Library/NET/Word-document/Iterating-Word-document-elements.md
@@ -7,7 +7,7 @@ documentation: UG
---
# Iterating Word document elements
-The following are the important points to be remembered while iterating the document elements
+The following are the important points to be remembered while iterating the document elements.
* Document consists of one or more sections.
* Section contains the contents present in Headers, Footers and main document through the instances of [WTextBody](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WTextBody.html).
@@ -28,7 +28,7 @@ using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Autom
{
foreach (WSection section in document.Sections)
{
- //Accesses the Body of section where all the contents in document are apart
+ //Accesses the Body of section where all the contents in document reside
WTextBody sectionBody = section.Body;
IterateTextBody(sectionBody);
WHeadersFooters headersFooters = section.HeadersFooters;
@@ -41,6 +41,8 @@ using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Autom
document.Save(stream, FormatType.Docx);
//Closes the Word document
document.Close();
+ //Saves the MemoryStream to a file
+ File.WriteAllBytes("Result.docx", stream.ToArray());
}
{% endhighlight %}
@@ -50,7 +52,7 @@ WordDocument document = new WordDocument("Template.docx");
//Processes the body contents for each section in the Word document
foreach (WSection section in document.Sections)
{
- //Accesses the Body of section where all the contents in document are apart
+ //Accesses the Body of section where all the contents in document reside
WTextBody sectionBody = section.Body;
IterateTextBody(sectionBody);
WHeadersFooters headersFooters = section.HeadersFooters;
@@ -69,7 +71,7 @@ document.Close();
Dim document As New WordDocument("Template.docx")
'Processes the body contents for each section in the Word document
For Each section As WSection In document.Sections
- 'Accesses the Body of section where all the contents in document are apart
+ 'Accesses the Body of section where all the contents in document reside
Dim sectionBody As WTextBody = section.Body
IterateTextBody(sectionBody)
Dim headersFooters As WHeadersFooters = section.HeadersFooters
@@ -118,7 +120,7 @@ private static void IterateTextBody(WTextBody textBody)
break;
case EntityType.BlockContentControl:
BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
- //Iterates to the body items of Block Content Control.
+ //Iterates through the body items of Block Content Control.
IterateTextBody(blockContentControl.TextBody);
break;
}
@@ -155,7 +157,7 @@ private static void IterateTextBody(WTextBody textBody)
break;
case EntityType.BlockContentControl:
BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
- //Iterates to the body items of Block Content Control.
+ //Iterates through the body items of Block Content Control.
IterateTextBody(blockContentControl.TextBody);
break;
}
@@ -171,7 +173,7 @@ For i As Integer = 0 To textBody.ChildEntities.Count - 1
'Accesses the body items (should be either paragraph, table or block content control) as IEntity
Dim bodyItemEntity As IEntity = textBody.ChildEntities(i)
'A Text body has 3 types of elements - Paragraph, Table and Block Content Control
- 'decide the element type using EntityType
+ 'Determines the element type using EntityType
Select Case bodyItemEntity.EntityType
Case EntityType.Paragraph
Dim paragraph As WParagraph = TryCast(bodyItemEntity, WParagraph)
@@ -188,7 +190,7 @@ For i As Integer = 0 To textBody.ChildEntities.Count - 1
Exit Select
Case EntityType.BlockContentControl
Dim BlockContentControl As BlockContentControl = TryCast(bodyItemEntity, BlockContentControl)
- 'Iterates to the body items of Block Content Control.
+ 'Iterates through the body items of Block Content Control.
IterateTextBody(BlockContentControl.TextBody)
Exit Select
End Select
@@ -256,7 +258,7 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
## Modify Hyperlink Uri
-The following code example shows how to iterate throughout the paragraph and modify the hyperlink ([Hyperlink](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.Hyperlink.html)) Uri and specific text ([WTextRange](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.Hyperlink.html)) with another.
+The following code example shows how to iterate throughout the paragraph and modify the hyperlink ([Hyperlink](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.Hyperlink.html)) Uri and specific text ([WTextRange](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WTextRange.html)) with another. The sample also replaces the text "Andrew" with "Fuller" and updates any hyperlink whose display text is "HTML" to point to `http://www.w3schools.com/`. These values are sample-specific; update them to suit your document.
{% tabs %}
@@ -267,7 +269,7 @@ using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Autom
{
foreach (WSection section in document.Sections)
{
- //Accesses the Body of section where all the contents in document are apart
+ //Accesses the Body of section where all the contents in document reside
WTextBody sectionBody = section.Body;
IterateTextBody(sectionBody);
WHeadersFooters headersFooters = section.HeadersFooters;
@@ -280,6 +282,8 @@ using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Autom
document.Save(stream, FormatType.Docx);
//Closes the Word document
document.Close();
+ //Saves the MemoryStream to a file
+ File.WriteAllBytes("Result.docx", stream.ToArray());
}
{% endhighlight %}
@@ -289,11 +293,11 @@ WordDocument document = new WordDocument("Template.docx");
//Processes the body contents for each section in the Word document
foreach (WSection section in document.Sections)
{
- //Accesses the Body of section where all the contents in document are apart
+ //Accesses the Body of section where all the contents in document reside
WTextBody sectionBody = section.Body;
IterateTextBody(sectionBody);
WHeadersFooters headersFooters = section.HeadersFooters;
- //consider that OddHeader & OddFooter are applied to this document
+ //Consider that OddHeader and OddFooter are applied to this document
//Iterates through the TextBody of OddHeader and OddFooter
IterateTextBody(headersFooters.OddHeader);
IterateTextBody(headersFooters.OddFooter);
@@ -307,12 +311,13 @@ document.Close();
Dim document As New WordDocument("Template.docx")
'Processes the body contents for each section in the Word document
For Each section As WSection In document.Sections
- 'Accesses the Body of section where all the contents in document are apart
+ 'Accesses the Body of section where all the contents in document reside
Dim sectionBody As WTextBody = section.Body
IterateTextBody(sectionBody)
Dim headersFooters As WHeadersFooters = section.HeadersFooters
- 'Considers that OddHeader and OddFooter are applied to this document
- 'Iterates through the TextBody of OddHeader and OddFooterIterateTextBody(headersFooters.OddHeader)
+ 'Assume that OddHeader and OddFooter are applied to this document
+ 'Iterates through the TextBody of OddHeader and OddFooter
+ IterateTextBody(headersFooters.OddHeader)
IterateTextBody(headersFooters.OddFooter)
Next
'Saves and closes the document instance
@@ -352,7 +357,7 @@ private static void IterateTextBody(WTextBody textBody)
break;
case EntityType.BlockContentControl:
BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
- //Iterates to the body items of Block Content Control.
+ //Iterates through the body items of Block Content Control.
IterateTextBody(blockContentControl.TextBody);
break;
}
@@ -386,7 +391,7 @@ private static void IterateTextBody(WTextBody textBody)
break;
case EntityType.BlockContentControl:
BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
- //Iterates to the body items of Block Content Control.
+ //Iterates through the body items of Block Content Control.
IterateTextBody(blockContentControl.TextBody);
break;
}
@@ -417,7 +422,7 @@ For i As Integer = 0 To textBody.ChildEntities.Count - 1
Exit Select
Case EntityType.BlockContentControl
Dim BlockContentControl As BlockContentControl = TryCast(bodyItemEntity, BlockContentControl)
- 'Iterates to the body items of Block Content Control.
+ 'Iterates through the body items of Block Content Control.
IterateTextBody(BlockContentControl.TextBody)
Exit Select
End Select
@@ -517,17 +522,17 @@ private static void IterateParagraph(ParagraphItemCollection paraItems)
}
break;
case EntityType.TextBox:
- //Iterates to the body items of textbox.
+ //Iterates through the body items of textbox.
WTextBox textBox = entity as WTextBox;
IterateTextBody(textBox.TextBoxBody);
break;
case EntityType.Shape:
- //Iterates to the body items of shape.
+ //Iterates through the body items of shape.
Shape shape = entity as Shape;
IterateTextBody(shape.TextBody);
break;
case EntityType.InlineContentControl:
- //Iterates to the paragraph items of inline content control.
+ //Iterates through the paragraph items of inline content control.
InlineContentControl inlineContentControl = entity as InlineContentControl;
IterateParagraph(inlineContentControl.ParagraphItems);
break;
@@ -568,17 +573,17 @@ private static void IterateParagraph(ParagraphItemCollection paraItems)
}
break;
case EntityType.TextBox:
- //Iterates to the body items of textbox.
+ //Iterates through the body items of textbox.
WTextBox textBox = entity as WTextBox;
IterateTextBody(textBox.TextBoxBody);
break;
case EntityType.Shape:
- //Iterates to the body items of shape.
+ //Iterates through the body items of shape.
Shape shape = entity as Shape;
IterateTextBody(shape.TextBody);
break;
case EntityType.InlineContentControl:
- //Iterates to the paragraph items of inline content control.
+ //Iterates through the paragraph items of inline content control.
InlineContentControl inlineContentControl = entity as InlineContentControl;
IterateParagraph(inlineContentControl.ParagraphItems);
break;
@@ -613,17 +618,17 @@ For i As Integer = 0 To paraItems.Count - 1
End If
Exit Select
Case EntityType.TextBox
- 'Iterates to the body items of textbox.
+ 'Iterates through the body items of textbox.
Dim textBox As WTextBox = TryCast(entity, WTextBox)
IterateTextBody(textBox.TextBoxBody)
Exit Select
Case EntityType.Shape
- 'Iterates to the body items of shape.
+ 'Iterates through the body items of shape.
Dim shape As Shape = TryCast(entity, Shape)
IterateTextBody(shape.TextBody)
Exit Select
Case EntityType.InlineContentControl
- 'Iterates to the paragraph items of inline content control.
+ 'Iterates through the paragraph items of inline content control.
Dim inlineContentControl As InlineContentControl = TryCast(entity, InlineContentControl)
IterateParagraph(inlineContentControl.ParagraphItems)
Exit Select
diff --git a/Document-Processing/Word/Word-Library/NET/Word-document/Merging-Word-documents.md b/Document-Processing/Word/Word-Library/NET/Word-document/Merging-Word-documents.md
index 21b8ea0ad2..1e1606f1ab 100644
--- a/Document-Processing/Word/Word-Library/NET/Word-document/Merging-Word-documents.md
+++ b/Document-Processing/Word/Word-Library/NET/Word-document/Merging-Word-documents.md
@@ -7,11 +7,13 @@ documentation: UG
---
# Merging Word documents
-You can merge multiple Word documents into single Word document by using DocIO’s capability of importing contents from one document to another. The imported contents are appended at the end of document.
+You can merge multiple Word documents into a single Word document by using DocIO’s capability of importing contents from one document to another. The imported contents are appended at the end of the document.
+
+By default, the imported contents start on a new page. You can also merge the contents on the same page by adjusting the source document’s first section break, as shown in the following sections.
## Assemblies and NuGet packages required
-Refer to the following links for assemblies and NuGet packages required based on platforms to merge Word documents using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO).
+Refer to the following links for the assemblies and NuGet packages required for each platform to merge Word documents using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO).
* [Merge Word documents assemblies](https://help.syncfusion.com/document-processing/word/word-library/net/assemblies-required)
* [Merge Word documents NuGet packages](https://help.syncfusion.com/document-processing/word/word-library/net/nuget-packages-required)
@@ -19,25 +21,25 @@ Refer to the following links for assemblies and NuGet packages required based on
To quickly start merging Word documents, please check out this video:
{% youtube "https://www.youtube.com/watch?v=atOSwzidmdw" %}
-## Merge document in new page
+## Merging documents in a new page
-The following code example illustrates how to import the contents from source document into destination document where the contents are appended.
+The following code example illustrates how to import the contents from a source document into a destination document where the contents are appended.
N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications.
{% tabs %}
-{% highlight C# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Word-document/Merge-documents-in-new-page/.NET/Merge-documents-in-new-page/Program.cs" %}
+{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Word-document/Merge-documents-in-new-page/.NET/Merge-documents-in-new-page/Program.cs" %}
FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
-//Opens an source document from file system through constructor of WordDocument class
+//Opens a source document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic))
{
//Opens the destination document
WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Docx);
//Imports the contents of source document at the end of destination document
destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles);
- //Saves and closes the destination document to MemoryStream
+ //Saves and closes the destination document to a MemoryStream
MemoryStream stream = new MemoryStream();
destinationDocument.Save(stream, FormatType.Docx);
destinationDocument.Close();
@@ -54,7 +56,7 @@ WordDocument destinationDocument = new WordDocument(targetFileName);
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);
//Saves the destination document
destinationDocument.Save(outputFileName, FormatType.Docx);
-//closes the document instances
+//Closes the document instances
sourceDocument.Close();
destinationDocument.Close();
{% endhighlight %}
@@ -68,7 +70,7 @@ Dim destinationDocument As New WordDocument(targetFileName)
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles)
'Saves the destination document
destinationDocument.Save(outputFileName, FormatType.Docx)
-'closes the document instances
+'Closes the document instances
sourceDocument.Close()
destinationDocument.Close()
{% endhighlight %}
@@ -79,25 +81,25 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
In the resultant document, the imported contents start from a new page followed by existing contents in a destination document. This is the default behavior.
-## Merge document in same page
+## Merging documents on the same page
-When your requirement is to append the contents from the same page instead of starting from a new page, you need to set the break code of first section of Source document as [NoBreak](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.SectionBreakCode.html). The following code example illustrates the importing contents from the same page.
+When your requirement is to append the contents on the same page instead of starting from a new page, you need to set the break code of the first section of the source document as [NoBreak](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.SectionBreakCode.html). The following code example illustrates how to import the contents on the same page.
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Word-document/Merge-documents-in-same-page/.NET/Merge-documents-in-same-page/Program.cs" %}
FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
-//Opens an source document from file system through constructor of WordDocument class
+//Opens a source document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic))
{
//Opens the destination document
WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Docx);
- //Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
+ //Sets the break code of the first section of the source document as NoBreak to avoid importing from a new page
document.Sections[0].BreakCode = SectionBreakCode.NoBreak;
//Imports the contents of source document at the end of destination document
destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles);
- //Saves and closes the destination document to MemoryStream
+ //Saves and closes the destination document to a MemoryStream
MemoryStream stream = new MemoryStream();
destinationDocument.Save(stream, FormatType.Docx);
destinationDocument.Close();
@@ -110,7 +112,7 @@ using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Aut
WordDocument sourceDocument = new WordDocument(sourceFileName);
//Opens the destination document
WordDocument destinationDocument = new WordDocument(targetFileName);
-//Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
+//Sets the break code of the first section of the source document as NoBreak to avoid importing from a new page
sourceDocument.Sections[0].BreakCode = SectionBreakCode.NoBreak;
//Imports the contents of source document at the end of destination document
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);
@@ -126,7 +128,7 @@ destinationDocument.Close();
Dim sourceDocument As New WordDocument(sourceFileName)
'Opens the destination document
Dim destinationDocument As New WordDocument(targetFileName)
-'Sets the break-code of first section of source document as NoBreak to avoid imported from a new page
+'Sets the break code of the first section of the source document as NoBreak to avoid importing from a new page
sourceDocument.Sections(0).BreakCode = SectionBreakCode.NoBreak
'Imports the contents of source document at the end of destination document
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles)
@@ -141,7 +143,7 @@ destinationDocument.Close()
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-document/Merge-documents-in-same-page).
-## Maintain Imported List style information
+## Maintain imported list style information
The following code example shows how to maintain information about imported list styles in a Word document while cloning and merging multiple Word documents.
@@ -228,6 +230,8 @@ destinationDocument.Close()
{% endtabs %}
+
+
## See Also
* [How to merge multiple Word documents in C#, VB.NET](https://support.syncfusion.com/kb/article/11499/how-to-merge-multiple-word-documents-in-c-vb-net)
diff --git a/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md b/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md
index c485556971..1793fa3273 100644
--- a/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md
+++ b/Document-Processing/Word/Word-Library/NET/Word-document/Print-Word-documents.md
@@ -1,6 +1,6 @@
---
title: Print Word documents in C# | DocIO | Syncfusion
-description: Learn how to print the Word documents into one using .NET Word (DocIO) library without Microsoft Word or interop dependencies.
+description: Learn how to print Word documents using the .NET Word (DocIO) library without Microsoft Word or interop dependencies.
platform: document-processing
control: DocIO
documentation: UG
@@ -9,7 +9,7 @@ documentation: UG
You can print a Word document by utilizing DocIO’s capability to convert the document into images and .NET framework’s [PrintDocument](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument?view=dotnet-plat-ext-7.0&viewFallbackFrom=net-5.0) class
-Initially you have to render the pages as images as shown below
+Initially you have to render the pages of the Word document as images, as shown below.
N> Refer to the appropriate tabs in the code snippets section: ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications.
@@ -20,7 +20,7 @@ N> Refer to the appropriate tabs in the code snippets section: ***C# [Windows-sp
WordDocument document = new WordDocument((string)this.textBox.Tag);
//Renders the Word document as image
Image[] images = document.RenderAsImages(ImageType.Metafile);
-//Closes the Word Document
+//Closes the Word document
document.Close();
{% endhighlight %}
@@ -29,15 +29,18 @@ document.Close();
Dim document As New WordDocument(DirectCast(Me.textBox.Tag, String))
'Renders the Word document as image
Dim images As Image() = document.RenderAsImages(ImageType.Metafile)
-'Closes the Word Document
+'Closes the Word document
document.Close()
{% endhighlight %}
{% endtabs %}
-You can specify the printer settings and page settings through the [PrintDocument](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument?view=net-5.0) class. The [PrintDocument.PrintPage](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument?view=dotnet-plat-ext-7.0&viewFallbackFrom=net-5.0) event should be handled to layout the document for printing.
+## Configuring print settings
-The following code example demonstrates how to print the Word document pages that have been rendered as an image:
+You can specify the printer settings and page settings through the [PrintDocument](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument?view=net-11.0-pp) class. The [PrintDocument.PrintPage](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument.printpage?view=net-11.0-pp) event should be handled to layout the document for printing. The following code example demonstrates how to print the Word document pages that have been rendered as an image, using the `images` array produced in the previous snippet.
+
+
+N> `startPageIndex` must be declared as a class-level integer field (initialize it to `0`). The snippet updates it based on the page range chosen in the print dialog.
{% tabs %}
@@ -66,7 +69,7 @@ if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
endPageIndex = printDialog.PrinterSettings.ToPage;
//Hooks the PrintPage event to handle the drawing pages for printing
printDialog.Document.PrintPage += new PrintPageEventHandler(PrintPageMethod);
- //Print the document
+ //Prints the document
printDialog.Document.Print();
}
}
@@ -87,14 +90,14 @@ printDialog.PrinterSettings.FromPage = 1
printDialog.PrinterSettings.ToPage = images.Length
'Opens the print dialog box
If printDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
- 'Checks whether the selected page range is valid or not
+ 'Checks whether the selected page range is valid
If printDialog.PrinterSettings.FromPage > 0 AndAlso printDialog.PrinterSettings.ToPage <= images.Length Then
'Updates the start page of the document to print
startPageIndex = printDialog.PrinterSettings.FromPage - 1
'Updates the end page of the document to print
endPageIndex = printDialog.PrinterSettings.ToPage
'Hooks the PrintPage event to handle the drawing pages for printing
- printDialog.Document.PrintPage += New PrintPageEventHandler(PrintPageMethod)
+ AddHandler printDialog.Document.PrintPage, AddressOf PrintPageMethod
'Prints the document
printDialog.Document.Print()
End If
@@ -184,6 +187,8 @@ End Sub
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-document/Print-Word-document).
+N> If `RenderAsImages` returns an empty array (for example, an empty document), skip printing and check the input document. Ensure the rendered array length is validated before configuring the page range.
+
## See Also
-* [How to do silent printing to print the Word document by rendering document pages as Image using Essential® DocIO](https://support.syncfusion.com/kb/article/4546/how-to-do-silent-printing-to-print-the-word-document-by-rendering-document-pages-as-image)
\ No newline at end of file
+* [How to do silent printing to print the Word document by rendering document pages as image using DocIO](https://support.syncfusion.com/kb/article/4546/how-to-do-silent-printing-to-print-the-word-document-by-rendering-document-pages-as-image)
\ No newline at end of file
diff --git a/Document-Processing/Word/Word-Library/NET/Word-document/Split-Word-documents.md b/Document-Processing/Word/Word-Library/NET/Word-document/Split-Word-documents.md
index 7324de4a34..2755146367 100644
--- a/Document-Processing/Word/Word-Library/NET/Word-document/Split-Word-documents.md
+++ b/Document-Processing/Word/Word-Library/NET/Word-document/Split-Word-documents.md
@@ -7,9 +7,9 @@ documentation: UG
---
# Split Word documents
-The [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) allows you to split the large Word document into number of smaller word documents by the sections, headings, bookmarks, and placeholder text in programmatically.
+The [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) allows you to split a large Word document into a number of smaller Word documents by section, heading, bookmark, and placeholder text programmatically.
-By using this feature, you can be able to split/extract the necessary parts from the original document for further processing.
+By using this feature, you can split/extract the necessary parts from the original document for further processing.
You can save the resultant document as a Word document (DOCX, WordML, DOC), PDF, image, HTML, RTF, and more.
@@ -18,14 +18,16 @@ To quickly start splitting Word documents, please check out this video:
## Assemblies and NuGet packages required
-Refer to the following links for assemblies and NuGet packages required based on platforms to split Word documents using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO).
+Refer to the following links for the assemblies and NuGet packages required for each platform to split Word documents using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO).
* [Split Word documents assemblies](https://help.syncfusion.com/document-processing/word/word-library/net/assemblies-required)
* [Split Word documents NuGet packages](https://help.syncfusion.com/document-processing/word/word-library/net/nuget-packages-required)
+N> The code samples use the namespaces `Syncfusion.DocIO.DLS`, `System.IO`, and `System.Text.RegularExpressions`. Add the corresponding `using`/`Imports` directives for these namespaces before running the samples.
+
## Split by Section
-The following code example illustrates how to split the Word document by sections.
+The following code example illustrates how to split the Word document by section.
N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications.
@@ -33,8 +35,8 @@ N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-plat
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Word-document/Split-by-section/.NET/Split-by-section/Program.cs" %}
FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
-//Load the template document as stream
-using(WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
+//Load the template document as a stream
+using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Iterate each section from Word document
for (int i = 0; i < document.Sections.Count; i++)
@@ -43,11 +45,13 @@ using(WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
WordDocument newDocument = new WordDocument();
//Add cloned section into new Word document
newDocument.Sections.Add(document.Sections[i].Clone());
- //Saves the Word document to MemoryStream
- FileStream outputStream = new FileStream("Section" + i + ".docx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
- newDocument.Save(outputStream, FormatType.Docx);
- //Closes the document
- newDocument.Close();
+ //Saves the Word document to a file stream
+ using (FileStream outputStream = new FileStream("Section" + i + ".docx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
+ {
+ newDocument.Save(outputStream, FormatType.Docx);
+ //Closes the document
+ newDocument.Close();
+ }
}
}
{% endhighlight %}
@@ -63,7 +67,7 @@ using (WordDocument document = new WordDocument(@"Template.docx"))
WordDocument newDocument = new WordDocument();
//Add cloned section into new Word document
newDocument.Sections.Add(document.Sections[i].Clone());
- //Save and close the new Word documet
+ //Save and close the new Word document
newDocument.Save("Section" + i + ".docx");
newDocument.Close();
}
@@ -90,7 +94,7 @@ End Using
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-document/Split-by-section).
-## Split by Headings
+## Split by Heading
The following code example illustrates how to split the Word document by using headings.
@@ -99,13 +103,13 @@ The following code example illustrates how to split the Word document by using h
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Word-document/Split-by-heading/.NET/Split-by-heading/Program.cs" %}
using (FileStream inputStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read))
{
- //Load the template document as stream
+ //Load the template document as a stream
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
WordDocument newDocument = null;
WSection newSection = null;
int headingIndex = 0;
- /Iterate each section in the Word document.
+ //Iterate each section in the Word document.
foreach (WSection section in document.Sections)
{
// Clone the section and add into new document.
@@ -154,7 +158,7 @@ using (FileStream inputStream = new FileStream("Template.docx", FileMode.Open, F
private static WSection AddSection(WordDocument newDocument, WSection section)
{
- //Create new session based on original document
+ //Create a new section based on the original document
WSection newSection = section.Clone();
newSection.Body.ChildEntities.Clear();
//Remove the first page header.
@@ -200,8 +204,8 @@ using (WordDocument doc = new WordDocument("Template.docx"))
WordDocument newDocument = null;
WSection newSection = null;
int headingIndex = 0;
- /Iterate each section in the Word document.
- foreach (WSection section in document.Sections)
+ //Iterate each section in the Word document.
+ foreach (WSection section in doc.Sections)
{
// Clone the section and add into new document.
if (newDocument != null)
@@ -248,7 +252,7 @@ using (WordDocument doc = new WordDocument("Template.docx"))
private static WSection AddSection(WordDocument newDocument, WSection section)
{
- //Create new session based on original document
+ //Create a new section based on the original document
WSection newSection = section.Clone();
newSection.Body.ChildEntities.Clear();
//Remove the first page header.
@@ -276,7 +280,7 @@ private static void AddEntity(WSection newSection, Entity entity)
private static void SaveWordDocument(WordDocument newDocument, string fileName)
{
- //Save file stream as Word document
+ //Save the new Word document
newDocument.Save(fileName, FormatType.Docx);
//Closes the document
newDocument.Close();
@@ -291,7 +295,7 @@ Using doc As WordDocument = New WordDocument("Template.docx")
Dim newSection As WSection = Nothing
Dim headingIndex = 0
'Iterate each section in the Word document.
- For Each section As WSection In document.Sections
+ For Each section As WSection In doc.Sections
' Clone the section and add into new document.
If newDocument IsNot Nothing Then newSection = AddSection(newDocument, section)
'Iterate each child entity in the Word document.
@@ -302,7 +306,7 @@ Using doc As WordDocument = New WordDocument("Template.docx")
Dim paragraph As WParagraph = TryCast(item, WParagraph)
'If paragraph has Heading 1 style, then save the traversed content as separate document.
'And create new document for new heading content.
- If paragraph.StyleName Is "Heading 1" Then
+ If paragraph.StyleName = "Heading 1" Then
If newDocument IsNot Nothing Then
'Saves the Word document
Dim fileName As String = "Document" & (headingIndex + 1).ToString() & ".docx"
@@ -359,7 +363,8 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
## Split by Bookmark
-The following code example illustrates how to split the Word document using bookmarks.
+The following code example illustrates how to split the Word document using bookmarks. The [`BookmarksNavigator.MoveToBookmark`](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BookmarksNavigator.html) API moves the virtual cursor to a bookmark, and [`GetContent`](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BookmarksNavigator.html) returns the bookmark range as a `WordDocumentPart`; calling `WordDocumentPart.GetAsWordDocument()` produces a standalone `WordDocument` containing the bookmark's contents.
+
{% tabs %}
@@ -374,7 +379,7 @@ using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)
//Iterate each bookmark in Word document.
foreach (Bookmark bookmark in bookmarkCollection)
{
- //Move the virtual cursor to the location before the end of the bookmark.
+ //Move the virtual cursor to the bookmark.
bookmarksNavigator.MoveToBookmark(bookmark.Name);
//Get the bookmark content as WordDocumentPart.
WordDocumentPart documentPart = bookmarksNavigator.GetContent();
@@ -401,7 +406,7 @@ using (WordDocument document = new WordDocument("Template.docx", FormatType.Docx
//Iterate each bookmark in Word document.
foreach (Bookmark bookmark in bookmarkCollection)
{
- //Move the virtual cursor to the location before the end of the bookmark.
+ //Move the virtual cursor to the bookmark.
bookmarksNavigator.MoveToBookmark(bookmark.Name);
//Get the bookmark content as WordDocumentPart.
WordDocumentPart documentPart = bookmarksNavigator.GetContent();
@@ -422,7 +427,7 @@ Using document As WordDocument = New WordDocument("Template.docx", FormatType.Do
Dim bookmarkCollection As BookmarkCollection = document.Bookmarks
'Iterate each bookmark in Word document.
For Each bookmark As Bookmark In bookmarkCollection
- 'Move the virtual cursor to the location before the end of the bookmark.
+ 'Move the virtual cursor to the bookmark.
bookmarksNavigator.MoveToBookmark(bookmark.Name)
'Get the bookmark content as WordDocumentPart.
Dim documentPart As WordDocumentPart = bookmarksNavigator.GetContent()
@@ -644,4 +649,4 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
* Explore how to split a Word document by section using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) in a live demo [here](https://document.syncfusion.com/demos/word/splitbysection#/tailwind).
* See how to split a Word document by heading using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) in a live demo [here](https://document.syncfusion.com/demos/word/splitbyheading#/tailwind).
* See how to split a Word document by bookmark using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) in a live demo [here](https://document.syncfusion.com/demos/word/splitbybookmark#/tailwind).
-* See how to split a Word document by placeholder using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) in a live demo [here](https://document.syncfusion.com/demos/word/splitbyplaceholder#/tailwind).
\ No newline at end of file
+* See how to split a Word document by placeholder text using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) in a live demo [here](https://document.syncfusion.com/demos/word/splitbyplaceholder#/tailwind).
diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md
index dd4639a7d6..6268a86a38 100644
--- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md
+++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-events.md
@@ -6,17 +6,17 @@ control: DocIO
documentation: UG
---
-# Event support for Mail merge
+# Event support for Mail merge in Word Library
-The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides event support to customize the document contents and merging image data during the Mail merge process. The following events are supported by Essential® DocIO during Mail merge process:
+The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides event support to customize the document contents and merge image data during the Mail merge process. The following events are supported by Syncfusion® DocIO during Mail merge process:
-* [MergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeFieldEventHandler.html)- occurs when a **Mail merge field** except image Mail merge field is encountered.
+* [MergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeFieldEventHandler.html) — occurs when a **Mail merge field** except image Mail merge field is encountered.
-* [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html)- occurs when an **image Mail merge field** is encountered.
+* [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html) — occurs when an **image Mail merge field** is encountered.
-* [BeforeClearField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearFieldEventHandler.html)- occurs when an **unmerged field** is encountered.
+* [BeforeClearField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearFieldEventHandler.html) — occurs when an **unmerged field** is encountered.
-* [BeforeClearGroupField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearGroupFieldEventHandler.html)- occurs when an **unmerged group field** is encountered.
+* [BeforeClearGroupField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearGroupFieldEventHandler.html) — occurs when an **unmerged group field** is encountered.
## MergeField Event
@@ -106,8 +106,8 @@ End Sub
{% endtabs %}
-N> 1. While executing mail merge, DocIO internally uses a copy of a particular region for populating the contents. Sometimes, unexpected problems may arise due to inserting multiple body items into the region through the mail merge process. So, to insert multiple body items using the merge field event handler, you are recommended to use this [approach](https://www.syncfusion.com/kb/11701/how-to-replace-merge-field-with-html-string-using-mail-merge) at your side.
-N> 2. The [ExecuteGroup(DataTable)](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteGroup_System_Data_DataTable_) method is not supported on the UWP platform.
+N> 1. While executing mail merge, DocIO internally uses a copy of a particular region for populating the contents. Sometimes, unexpected problems may arise due to inserting multiple body items into the region through the mail merge process. So, to insert multiple body items using the merge field event handler, we recommend using this [approach](https://www.syncfusion.com/kb/11701/how-to-replace-merge-field-with-html-string-using-mail-merge).
+N> 2. The [ExecuteGroup(DataTable)](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteGroup_System_Data_DataTable_) method is not supported on the UWP platform. The cross-platform sample above is not valid for UWP; use an alternative data-binding approach on UWP.
The following code example shows GetDataTable method which is used to get data for mail merge.
@@ -170,7 +170,7 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
You can format the merged image like resizing the image and more during mail merge process using the [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html) Event.
-N> The [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html) event triggers only for image merge fields. Ensure you have a valid image merge field in the template document, following the syntax: **{ MERGEFIELD Image:logo }**.
+N> The [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html) event triggers only for image merge fields. Ensure you have a valid image merge field in the template document, following the syntax: **{ MERGEFIELD Image:Logo }**.
The following code example shows how to use the [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html) event during Mail merge process.
@@ -183,9 +183,9 @@ WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
//Uses the mail merge events handler for image fields
document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_ProductImage);
//Specifies the field names and field values
-string[] fieldNames = new string[] { "Logo"};
-string[] fieldValues = new string[] { "Logo.png"};
-//Executes the mail merge with groups
+string[] fieldNames = new string[] { "Logo" };
+string[] fieldValues = new string[] { "Logo.png" };
+//Executes the mail merge
document.MailMerge.Execute(fieldNames, fieldValues);
//Saves the Word document to MemoryStream
MemoryStream stream = new MemoryStream();
@@ -200,9 +200,9 @@ WordDocument document = new WordDocument("Template.docx");
//Uses the mail merge events handler for image fields
document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_ProductImage);
//Specifies the field names and field values
-string[] fieldNames = new string[] { "Logo"};
-string[] fieldValues = new string[] { "Logo.png"};
-//Executes the mail merge with groups
+string[] fieldNames = new string[] { "Logo" };
+string[] fieldValues = new string[] { "Logo.png" };
+//Executes the mail merge
document.MailMerge.Execute(fieldNames, fieldValues);
//Saves and closes WordDocument instance
document.Save("Sample.docx");
@@ -217,7 +217,7 @@ AddHandler document.MailMerge.MergeImageField, AddressOf MergeField_ProductImage
'Specifies the field names and field values
Dim fieldNames As String() = New String() {"Logo"}
Dim fieldValues As String() = New String() {"Logo.png"}
-'Executes the mail merge with groups
+'Executes the mail merge
document.MailMerge.Execute(fieldNames, fieldValues)
'Saves and closes WordDocument instance
document.Save("Sample.docx")
@@ -298,10 +298,10 @@ The following code example shows how to use the [BeforeClearField](https://help.
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Event-to-bind-data-for-unmerged-fields/.NET/Event-to-bind-data-for-unmerged-fields/Program.cs" %}
//Opens the template document
FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
-WordDocument document = new WordDocument(fileStreamPath);
-//Sets “ClearFields” to true to remove empty mail merge fields from document
+WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
+//Sets “ClearFields” to false to keep empty mail merge fields in the document
document.MailMerge.ClearFields = false;
-//Uses the mail merge event to clear the unmerged field while perform mail merge execution
+//Uses the mail merge event to clear the unmerged field while performing mail merge execution
document.MailMerge.BeforeClearField += new BeforeClearFieldEventHandler(BeforeClearFieldEvent);
//Execute mail merge
document.MailMerge.ExecuteGroup(GetDataTable());
@@ -315,9 +315,9 @@ document.Close();
{% highlight c# tabtitle="C# [Windows-specific]" %}
//Opens the template document
WordDocument document = new WordDocument("Template.docx");
-//Sets “ClearFields” to true to remove empty mail merge fields from document
+//Sets “ClearFields” to false to keep empty mail merge fields in the document
document.MailMerge.ClearFields = false;
-//Uses the mail merge event to clear the unmerged field while perform mail merge execution
+//Uses the mail merge event to clear the unmerged field while performing mail merge execution
document.MailMerge.BeforeClearField += new BeforeClearFieldEventHandler(BeforeClearFieldEvent);
//Execute mail merge
document.MailMerge.ExecuteGroup(GetDataTable());
@@ -329,10 +329,10 @@ document.Close();
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Opens the template document
Dim document As WordDocument = New WordDocument("Template.docx")
-'Sets “ClearFields” to true to remove empty mail merge fields from document
+'Sets “ClearFields” to false to keep empty mail merge fields in the document
document.MailMerge.ClearFields = False
-'Uses the mail merge event to clear the unmerged field while perform mail merge execution
-document.MailMerge.BeforeClearField += New BeforeClearFieldEventHandler(AddressOf BeforeClearField)
+'Uses the mail merge event to clear the unmerged field while performing mail merge execution
+AddHandler document.MailMerge.BeforeClearField, AddressOf BeforeClearFieldEvent
'Execute mail merge
document.MailMerge.ExecuteGroup(GetDataTable())
'Saves and closes the WordDocument instance
@@ -559,13 +559,13 @@ document.Close();
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Opens the template document
Dim document As WordDocument = New WordDocument("Template.docx")
-'Sets “ClearFields” to true to remove empty mail merge fields from document
+'Sets “ClearFields” to false to keep empty mail merge fields in the document
document.MailMerge.ClearFields = False
-'Uses the mail merge event to clear the unmerged field while perform mail merge execution
+'Uses the mail merge event to clear the unmerged field while performing mail merge execution
AddHandler document.MailMerge.BeforeClearGroupField, AddressOf BeforeClearFields
'Gets the employee details as “IEnumerable” collection
Dim employeeList As List(Of Employees) = GetEmployees()
-'Creates an instance of MailMergeDataTableby specifying mail merge group name and “IEnumerable” collection
+'Creates an instance of MailMergeDataTable by specifying mail merge group name and “IEnumerable” collection
Dim dataTable As MailMergeDataTable = New MailMergeDataTable("Employees", employeeList)
'Performs Mail merge
document.MailMerge.ExecuteNestedGroup(dataTable)
@@ -589,6 +589,7 @@ private static void BeforeClearFields(object sender, BeforeClearGroupFieldEventA
string[] groupName = args.GroupName.Split(':');
if (groupName[groupName.Length - 1] == "Orders")
{
+ //Gets the field names in the group
string[] fields = args.FieldNames;
List orderList = GetOrders();
//Binds the data to the unmerged fields in group as alternative values
@@ -626,16 +627,16 @@ private static void BeforeClearFields(object sender, BeforeClearGroupFieldEventA
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Private Sub BeforeClearFields(ByVal sender As Object, ByVal args As BeforeClearGroupFieldEventArgs)
If Not args.HasMappedGroupInDataSource Then
- ‘Gets the Current unmerged group name from the event argument
+ 'Gets the Current unmerged group name from the event argument
Dim groupName As String() = args.GroupName.Split(":"c)
If groupName(groupName.Length - 1) = "Orders" Then
'Gets the field names in the group
Dim fields As String() = args.FieldNames
Dim orderList As List(Of OrderDetails) = GetOrders()
- ‘Binds the data to the unmerged fields in group as alternative values
+ 'Binds the data to the unmerged fields in group as alternative values
args.AlternateValues = orderList
Else
- ‘If group value is empty, you can set whether the unmerged merge group field can be clear or not
+ 'If group value is empty, you can set whether the unmerged merge group field can be clear or not
args.ClearGroup = True
End If
End If
@@ -698,7 +699,7 @@ public static List GetEmployees()
'Gets orders list
Private Shared Function GetOrders() As List(Of OrderDetails)
Dim orders As List(Of OrderDetails) = New List(Of OrderDetails)()
- orders.Add(New OrderDetails("10835", New DateTime(2015, 1, 5), New DateTime(2015, 1, 12), New DateTime(2015, 1, 21)))
+ orders.Add(New OrderDetails("10952", New DateTime(2015, 2, 5), New DateTime(2015, 2, 12), New DateTime(2015, 2, 21)))
Return orders
End Function
diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md
index 220a6074e9..6ce9737417 100644
--- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md
+++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-group.md
@@ -6,9 +6,9 @@ control: DocIO
documentation: UG
---
-# Mail merge for a group
+# Mail Merge for a group in Word Library
-You can perform Mail merge and append multiple records from data source within a specified region to a template document. The region between start and end groups merge fields. It gets repeated for every record from the data source.
+You can perform Mail Merge and append multiple records from data source within a specified region to a template document. The region is bounded by start and end group merge fields. The region gets repeated for every record from the data source.
The following table illustrates the supported mail merge overloads for ExecuteGroup method.
@@ -35,28 +35,27 @@ The following table illustrates the supported mail merge overloads for ExecuteGr
## Create template for group mail merge
-The region where the Mail merge operations are to be performed must be marked by two merge fields with the following names.
+The region where the Mail Merge operations are to be performed must be marked by two merge fields with the following names.
* «TableStart:TableName» and «BeginGroup:GroupName» - For the entry point of the region.
-
* «TableEnd:TableName» and «EndGroup:GroupName» - For the end point of the region.
- 1. *TableStart* and *TableEnd* region is preferred for performing Mail merge inside the table cell.
- 2. *BeginGroup* and *EndGroup* region is preferred for performing Mail merge inside the document body contents.
+ * *TableStart* and *TableEnd* regions are preferred for performing Mail Merge inside the table cell.
+ * *BeginGroup* and *EndGroup* regions are preferred for performing Mail Merge inside the document body contents.
For example, consider that you have a template document as shown.

-In this template, Employees is the group name and the same name should be used while performing Mail merge through code. There are two special merge fields “TableStart:Employees” and “TableEnd:Employees” to denote the start and end of the Mail merge group.
+In this template, Employees is the group name and the same name should be used while performing Mail Merge through code. There are two special merge fields “TableStart:Employees” and “TableEnd:Employees” to denote the start and end of the Mail Merge group.
## Execute group mail merge
-The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides various overloads for [ExecuteGroup](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteGroup_System_Data_DataTable_) method to perform Mail merge within a group from various data sources.
+The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides various overloads for [ExecuteGroup](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteGroup_System_Data_DataTable_) method to perform Mail Merge within a group from various data sources.
-N> For group mail merge, declare a class with the field names, create a list, and pass it to [MailMergeDataTable](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteGroup_Syncfusion_DocIO_DLS_MailMergeDataTable_). Ensure that the property and field names in the input document match when creating the data table.
+N> For group mail merge, declare a class with the field names, create a list, and pass it to [MailMergeDataTable](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMergeDataTable.html). Ensure that the property and field names in the input document match when creating the data table.
-The following code example shows how to perform Mail merge in the specific region with **data source retrieved from SQL connection**.
+The following code example shows how to perform Mail Merge in the specific region with **data source retrieved from SQL connection**.
N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-platform]*** for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; ***C# [Windows-specific]*** for WinForms and WPF; ***VB.NET [Windows-specific]*** for VB.NET applications.
@@ -108,8 +107,8 @@ private DataTable GetDataTable()
adapter.Fill(dataset);
adapter.Dispose();
conn.Close();
- System.Data.DataTable table = dataset.Tables[0];
- //Sets table name as Employees for template merge field reference.
+ DataTable table = dataset.Tables[0];
+ //Sets the table name to "Employees" to match the template merge field.
table.TableName = "Employees";
return table;
}
@@ -125,7 +124,7 @@ Private Function GetDataTable() As DataTable
adapter.Dispose()
conn.Close()
Dim table As System.Data.DataTable = DataSet.Tables(0)
- 'Sets table name as Employees for template merge field reference.
+ 'Sets the table name to "Employees" to match the template merge field.
table.TableName = "Employees"
Return table
End Function
@@ -139,9 +138,9 @@ The resultant document looks as follows.

-## Mail merge with .NET objects
+## Mail Merge with .NET objects
-You can perform Mail merge with .NET objects in a template document. The following code snippet shows how to perform Mail merge with business objects.
+You can perform Mail Merge with .NET objects in a template document. The following code snippet shows how to perform Mail Merge with business objects.
{% tabs %}
@@ -149,9 +148,9 @@ You can perform Mail merge with .NET objects in a template document. The followi
//Opens the template document
FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
-//Gets the employee details as “IEnumerable” collection
+//Gets the employee details as IEnumerable collection
List employeeList = GetEmployees();
-//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
+//Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection
MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList);
//Uses the mail merge events handler for image fields.
document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_EmployeeImage);
@@ -179,9 +178,9 @@ private void MergeField_EmployeeImage(object sender, MergeImageFieldEventArgs ar
{% highlight c# tabtitle="C# [Windows-specific]" %}
//Opens the template document
WordDocument document = new WordDocument("Template.docx");
-//Gets the employee details as “IEnumerable” collection
+//Gets the employee details as IEnumerable collection
List employeeList = GetEmployees();
-//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
+//Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection
MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList);
//Uses the mail merge events handler for image fields.
document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_EmployeeImage);
@@ -207,9 +206,9 @@ private void MergeField_EmployeeImage(object sender, MergeImageFieldEventArgs ar
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Opens the template document
Dim document As New WordDocument("Template.docx")
-'Gets the employee details as “IEnumerable” collection
+'Gets the employee details as IEnumerable collection
Dim employeeList As List(Of Employee) = GetEmployees()
-'Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
+'Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection
Dim dataTable As New MailMergeDataTable("Employees", employeeList)
'Uses the mail merge events handler for image fields.
AddHandler document.MailMerge.MergeImageField, AddressOf MergeField_EmployeeImage
diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md
index 1d35ce169b..40a48c955c 100644
--- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md
+++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-for-nested-groups.md
@@ -6,9 +6,9 @@ control: DocIO
documentation: UG
---
-# Nested Mail merge for group
+# Mail merge for nested groups
-You can perform nested Mail merge with relational or hierarchical data source and independent data tables in a template document.
+You can perform nested mail merge with relational or hierarchical data source and independent data tables in a template document.
The following table illustrates the supported mail merge overloads for ExecuteNestedGroup method.
@@ -43,9 +43,9 @@ The following table illustrates the supported mail merge overloads for ExecuteNe
## Create template for nested group mail merge
-Nested Mail merge operation automatically replaces the merge field with immediate group data. You can also predefine the group data that is populated to a merge field.
-
-To execute nested mail merge, design your Word document template as follow.
+Nested mail merge operation automatically replaces the merge field with immediate group data. You can also predefine the group data that is populated in a merge field.
+
+To execute nested mail merge, design your Word document template as follows.

@@ -53,7 +53,7 @@ In this template, Employees is the owner group and it has two child groups Custo
## Execute nested group mail merge
-The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides various overloads for the [ExecuteNestedGroup](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteNestedGroup_System_Data_Common_DbConnection_System_Collections_ArrayList_) method to perform Mail merge for nested groups or regions in the Word document.
+The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides various overloads for the [ExecuteNestedGroup](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteNestedGroup_System_Data_Common_DbConnection_System_Collections_ArrayList_) method to perform mail merge for nested groups or regions in the Word document.
You need to define commands with the table name and expression for linking the multiple data tables **(explicit relation data)** during nested Mail merge process. You can use the “%TableName.ColumnName%” expression for getting the current value of specified column or field from the table.
@@ -154,7 +154,7 @@ The resultant document looks as follows.
Essential® DocIO allows you to perform Mail merge with the dynamic objects. The [ExpandoObject](https://docs.microsoft.com/en-us/dotnet/api/system.dynamic.expandoobject?view=net-6.0) is like a collection of key and value pairs, which means IDictionary. So, you can also use IDictionary collection instead of [ExpandoObject](https://docs.microsoft.com/en-us/dotnet/api/system.dynamic.expandoobject?view=net-6.0) to execute mail merge.
-The following code snippet shows how to perform the Mail merge with dynamic objects ([ExpandoObject](https://docs.microsoft.com/en-us/dotnet/api/system.dynamic.expandoobject?view=net-6.0)).
+The following code snippet shows how to perform the mail merge with dynamic objects ([ExpandoObject](https://learn.microsoft.com/en-us/dotnet/api/system.dynamic.expandoobject)).
{% tabs %}
@@ -170,7 +170,7 @@ dataSet.Add(dataTable);
dataTable = new MailMergeDataTable("Orders", GetOrders());
dataSet.Add(dataTable);
List commands = new List();
-//DictionaryEntry contain "Source table" (key) and "Command" (value)
+//DictionaryEntry contains "Source table" (key) and "Command" (value)
DictionaryEntry entry = new DictionaryEntry("Customers", string.Empty);
commands.Add(entry);
//Retrieves the customer details
@@ -196,7 +196,7 @@ dataSet.Add(dataTable);
dataTable = new MailMergeDataTable("Orders", GetOrders());
dataSet.Add(dataTable);
List commands = new List();
-//DictionaryEntry contain "Source table" (key) and "Command" (value)
+//DictionaryEntry contains "Source table" (key) and "Command" (value)
DictionaryEntry entry = new DictionaryEntry("Customers", string.Empty);
commands.Add(entry);
//Retrieves the customer details
@@ -220,7 +220,7 @@ dataSet.Add(dataTable)
dataTable = New MailMergeDataTable("Orders", GetOrders())
dataSet.Add(dataTable)
Dim commands As New List(Of DictionaryEntry)()
-'DictionaryEntry contain "Source table" (key) and "Command" (value)
+'DictionaryEntry contains "Source table" (key) and "Command" (value)
Dim entry As New DictionaryEntry("Customers", String.Empty)
commands.Add(entry)
'Retrieves the customer details
@@ -361,23 +361,28 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
## Mail merge with implicit relational data
-You can perform **nested Mail merge with implicit relational data** objects without any explicit relational commands by using the [ExecuteNestedGroup](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteNestedGroup_Syncfusion_DocIO_DLS_MailMergeDataTable_) overload method.
+You can perform **nested mail merge with implicit relational data** objects without any explicit relational commands by using the [ExecuteNestedGroup](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ExecuteNestedGroup_Syncfusion_DocIO_DLS_MailMergeDataTable_) overload method.
+
+DocIO automatically maps child collections to nested groups by matching the property name on the data object to the group name declared in the template (for example, a property named `Departments` on the `Organization` class maps to the `Departments` group region). Ensure property names match the group names used in the template.
-### Map the field of ancestor group
+### Map fields of ancestor groups
-You can also merge any field in the nested group by **mapping the field or column of its ancestor group or table** in the data source. To achieve this, you need to add a corresponding group name or table name as a prefix to the merge field name along with “:” separator.
+You can also merge any field in the nested group by **mapping the field or column of its ancestor group or table** in the data source. To achieve this, add the corresponding group name or table name as a prefix to the merge field name along with the `:` separator.
For example:
- * The merge field name should be like “TableName:Id” (<>)
- * The merge field name should be like “Image:TableName:Photo” (<>)
-
-For example, consider that you have a template document as follow.
+ * The merge field name should be like `TableName:Id` (<>)
+ * The merge field name should be like `Image:TableName:Photo` (<>)
+
+> **NOTE**
+> Image merge fields require the merge field to be configured with the `Image:` prefix in the template and the data value to be a byte array or `Image` instance.
+
+For example, consider that you have a template document as follows.

-In the above template, Organizations is the owner group and it has two child groups Departments and Employees. The Supervisor merge field of Departments group is used in Employees group.
+In the above template, Organizations is the owner group and it has two child groups Departments and Employees. The `Supervisor` merge field of the Departments group is used in the Employees group.
-The following code example shows how to perform nested Mail merge with the implicit relational data objects.
+The following code example shows how to perform nested mail merge with the implicit relational data objects.
{% tabs %}
@@ -385,9 +390,9 @@ The following code example shows how to perform nested Mail merge with the impli
//Opens the template document
FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
-//Gets the organization details as “IEnumerable” collection
+//Gets the organization details as IEnumerable collection
List organizationList = GetOrganizations();
-//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
+//Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection
MailMergeDataTable dataTable = new MailMergeDataTable("Organizations", organizationList);
//Performs Mail merge
document.MailMerge.ExecuteNestedGroup(dataTable);
@@ -401,9 +406,9 @@ document.Close();
{% highlight c# tabtitle="C# [Windows-specific]" %}
//Opens the template document
WordDocument document = new WordDocument("Template.docx");
-//Gets the organization details as “IEnumerable” collection
+//Gets the organization details as IEnumerable collection
List organizationList = GetOrganizations();
-//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
+//Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection
MailMergeDataTable dataTable = new MailMergeDataTable("Organizations", organizationList);
//Performs Mail merge
document.MailMerge.ExecuteNestedGroup(dataTable);
@@ -415,9 +420,9 @@ document.Close();
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Opens the template document
Dim document As WordDocument = New WordDocument("Template.docx")
-'Gets the organization details as “IEnumerable” collection
+'Gets the organization details as IEnumerable collection
Dim organizationList As List(Of Organization) = GetOrganizations()
-'Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
+'Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection
Dim dataTable As MailMergeDataTable = New MailMergeDataTable("Organizations", organizationList)
'Performs Mail merge
document.MailMerge.ExecuteNestedGroup(dataTable)
@@ -477,7 +482,7 @@ public static List GetOrganizations()
{% endhighlight %}
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
-Public Function GetOrganizations() As List(Of Organization)
+Public Shared Function GetOrganizations() As List(Of Organization)
'Creates Employee details
Dim employees As List(Of EmployeeDetails) = New List(Of EmployeeDetails)
employees.Add(New EmployeeDetails("Thomas Hardy", "1001", "05/27/1996"))
diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md
index 3336f510f3..697b56134d 100644
--- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md
+++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-options.md
@@ -8,11 +8,11 @@ documentation: UG
# Mail merge options in Word Library
-The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class allows you to customize the Mail merge process with the following options.
+The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class allows you to customize the mail merge process with the following options.
## Field Mapping
-The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class can automatically **maps the merge field names with data source column names** during Mail merge process. You can also customize the field mapping when the merge field names in the template document varies with the column names in the data source by using [MappedFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_MappedFields) collection.
+The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class can automatically **map the merge field names with data source column names** during mail merge process. You can also customize the field mapping when the merge field names in the template document vary with the column names in the data source by using [MappedFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_MappedFields) collection.
The following code example shows how to add mapping when a merge field name in a document and column name in data source have different names.
@@ -132,29 +132,29 @@ The following code example shows how to retrieve the merge field names for a spe
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Retrieve-merge-field-names/.NET/Retrieve-merge-field-names/Program.cs" %}
-//Gets the fields from the specified groups.
+//Gets the fields from the specified group.
string[] fieldNames = document.MailMerge.GetMergeFieldNames(groupName);
{% endhighlight %}
{% highlight c# tabtitle="C# [Windows-specific]" %}
-//Gets the fields from the specified groups
+//Gets the fields from the specified group
string[] fieldNames = document.MailMerge.GetMergeFieldNames(groupName);
{% endhighlight %}
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
-'Gets the fields from the specified groups
+'Gets the fields from the specified group
Dim fieldNames As String() = document.MailMerge.GetMergeFieldNames(groupName)
{% endhighlight %}
{% endtabs %}
-You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Retrieve-merge-field-names).
+You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Retrieve-merge-field-names). This sample demonstrates all three methods shown above (`GetMergeFieldNames`, `GetMergeGroupNames`, and `GetMergeFieldNames(groupName)`).
## Remove empty paragraphs
-You can remove the empty paragraphs when the paragraph has only a merge field item, without any data during Mail merge process.
+You can remove the empty paragraphs when the paragraph has only a merge field item, without any data during mail merge process.
-The following code example shows how to remove the empty paragraphs during Mail merge process.
+The following code example shows how to remove the empty paragraphs during mail merge process.
{% tabs %}
@@ -215,15 +215,15 @@ Essential® DocIO removes or keeps the unmerged merge fields in th
When a merge field is considered as unmerged during mail merge process?
-1. The merge field doesn't have mapping field in data source.
+1. The merge field doesn't have a mapping field in data source.
-2. The merge field has mapping field in data source, but the data is null or string.Empty.
+2. The merge field has a mapping field in data source, but the data is null or string.Empty.
-Mail merge operation automatically removes the unmerged merge fields since the default value of [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property is true.
+The mail merge operation automatically removes the unmerged merge fields since the default value of the [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property is true.
T> 1. Set [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property to false before the mail merge execution statement if your requirement is to keep the unmerged merge fields in the output document.
T> 2. Modify the [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property before each mail merge execution statement while performing multiple mail merge executions if your requirement is to remove the unmerged merge fields in one mail merge execution and keep the unmerged merge fields in another mail merge execution.
-T> 3. Order the mail merge executions with the [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property false as first to avoid removal merge fields that are required for next mail merge execution in the same document.
+T> 3. Order the mail merge executions with the [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property false as first to avoid removal of merge fields that are required for next mail merge execution in the same document.
T> 4. You can get the unmerged fields in your document, customize the mail merge process using the BeforeClearField Event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#beforeclearfield-event).
The following code example shows how to keep the unmerged merge fields in the generated Word document.
@@ -234,7 +234,7 @@ The following code example shows how to keep the unmerged merge fields in the ge
//Opens the template document
FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
-//Sets “ClearFields” to true to remove empty mail merge fields from document
+//Sets “ClearFields” to false to keep the unmerged mail merge fields in document
document.MailMerge.ClearFields = false;
string[] fieldNames = new string[] { "EmployeeId", "Phone", "City" };
string[] fieldValues = new string[] { "1001", "+91-9999999999", "London" };
@@ -250,7 +250,7 @@ document.Close();
{% highlight c# tabtitle="C# [Windows-specific]" %}
//Opens the template document
WordDocument document = new WordDocument("Template.docx");
-//Sets “ClearFields” to true to remove empty mail merge fields from document
+//Sets “ClearFields” to false to keep the unmerged mail merge fields in document
document.MailMerge.ClearFields = false;
string[] fieldNames = new string[] { "EmployeeId", "Phone", "City" };
string[] fieldValues = new string[] { "1001", "+91-9999999999", "London" };
@@ -264,7 +264,7 @@ document.Close();
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Opens the template document
Dim document As New WordDocument("Template.docx")
-'Sets “ClearFields” to true to remove empty mail merge fields from document
+'Sets “ClearFields” to false to keep the unmerged mail merge fields in document
document.MailMerge.ClearFields = False
Dim fieldNames As String() = New String() {"EmployeeId", "Phone", "City"}
Dim fieldValues As String() = New String() {"1001", "+91-9999999999", "London"}
@@ -281,7 +281,7 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
## Remove empty group
-You can remove the empty merge field groups which contains unmerged merge fields after executing mail merge for a group in a Word document.
+You can remove the empty merge field groups which contain unmerged merge fields after executing mail merge for a group in a Word document.
The following code example shows how to remove empty merge field group during mail merge process in a Word document.
@@ -544,15 +544,15 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
## Restart numbering in lists
-You can restart the list numbering for each records while performing mail merge for a group in Word document.
+You can restart the list numbering for each record while performing mail merge for a group in Word document (https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.ImportOptions.html).
-The following code example shows how to restart the list numbering in a Word documents while performing mail merge.
+The following code example shows how to restart the list numbering in a Word document while performing mail merge.
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Restart-list-numbering-in-mail-merge/.NET/Restart-list-numbering-in-mail-merge/Program.cs" %}
//Loads an existing Word document
-FileStream fileStream = new FileStream("Template.docx", FileMode.Open);
+FileStream fileStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
WordDocument document = new WordDocument(fileStream, FormatType.Docx);
//Sets ImportOptions to restart the list numbering
document.ImportOptions = ImportOptions.ListRestartNumbering;
@@ -583,7 +583,7 @@ employeeList.Add(new Employee("101", "Nancy Davolio", "Seattle, WA, USA"));
employeeList.Add(new Employee("102", "Andrew Fuller", "Tacoma, WA, USA"));
employeeList.Add(new Employee("103", "Janet Leverling", "Kirkland, WA, USA"));
//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
-MailMergeDataTable dataTable = new MailMergeDataTable("Employee", employeeList);
+MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList);
//Performs mail merge
document.MailMerge.ExecuteGroup(dataTable);
//Saves the Word document
@@ -603,7 +603,7 @@ employeeList.Add(New Employee("101", "Nancy Davolio", "Seattle, WA, USA"))
employeeList.Add(New Employee("102", "Andrew Fuller", "Tacoma, WA, USA"))
employeeList.Add(New Employee("103", "Janet Leverling", "Kirkland, WA, USA"))
'Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
-Dim dataTable As MailMergeDataTable = New MailMergeDataTable("Employee", employeeList)
+Dim dataTable As MailMergeDataTable = New MailMergeDataTable("Employees", employeeList)
'Performs mail merge
document.MailMerge.ExecuteGroup(dataTable)
'Saves the Word document
@@ -774,7 +774,7 @@ document.Close();
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Opens the template document
-Dim document As WordDocument = New WordDocument("Data/Template.docx")
+Dim document As WordDocument = New WordDocument("Template.docx")
'Creates a data table
Dim table As DataTable = New DataTable("CompatibleVersions")
table.Columns.Add("WordVersion")
@@ -867,7 +867,7 @@ document.Close()
{% endtabs %}
-The following code example shows how to skip merging particular image during mail merge process using MergeImageFieldEventHandler.
+The following code example shows how to skip merging particular image during mail merge process using [MergeImageFieldEventHandler](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html). For details on the event arguments, see [MergeImageFieldEventArgs](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventArgs.html) (members: `Skip`, `FieldName`, `FieldValue`, `ImageStream`, `ImageFileName`, `Picture`).
{% tabs %}
@@ -876,7 +876,10 @@ private void MergeEmployeePhoto(object sender, MergeImageFieldEventArgs args)
{
//Skip to merge particular image
if (args.FieldName == "Andrew")
+ {
args.Skip = true;
+ return;
+ }
//Sets image
string ProductFileName = args.FieldValue.ToString();
FileStream imageStream = new FileStream(ProductFileName, FileMode.Open, FileAccess.Read);
@@ -892,7 +895,10 @@ private void MergeEmployeePhoto(object sender, MergeImageFieldEventArgs args)
{
//Skip to merge particular image
if (args.FieldName == "Andrew")
+ {
args.Skip = true;
+ return;
+ }
//Sets image
args.ImageFileName = args.FieldValue.ToString();
}
@@ -903,6 +909,7 @@ Private Sub MergeEmployeePhoto(ByVal sender As Object, ByVal args As MergeImageF
'Skip to merge particular image
If args.FieldName = "Andrew" Then
args.Skip = True
+ Return
End If
'Sets image
Dim ProductFileName As String = args.FieldValue.ToString()
@@ -920,6 +927,8 @@ You can start a new page for each group of records while performing a mail merge
The following code example illustrates how to start a new page for each group of records during the mail merge process.
+N> The `GetInvoice` helper method and the `Invoice`, `Orders`, `Order`, and `OrderTotals` classes used by this snippet are shown below the tabs.
+
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Start-at-new-page/.NET/Start-at-new-page/Program.cs" %}
@@ -1105,7 +1114,7 @@ Public Function GetInvoice() As List(Of Invoice)
invoices.Add(New Invoice(orders, order, orderTotals))
orders = New List(Of Orders)()
- orders.Add(New Orders("10250", "Hanari Carnes", "Rua do Paço, 67", "Rio de Janeiro", "05454-876", "Brazil", "VINET", "Rua do Paço, "1996-07-04T00:00:00-04:00", "1996-08-01T00:00:00-04:00", "1996-07-16T00:00:00-04:00", "United Package"))
+ orders.Add(New Orders("10250", "Hanari Carnes", "Rua do Paço, 67", "Rio de Janeiro", "05454-876", "Brazil", "VINET", "Rua do Paço, 67", "51100", "Rio de Janeiro", "Brazil", "Margaret Peacock", "Hanari Carnes", "1996-07-04T00:00:00-04:00", "1996-08-01T00:00:00-04:00", "1996-07-16T00:00:00-04:00", "United Package"))
order = New List(Of Order)()
order.Add(New Order("65", "Louisiana Fiery Hot Pepper Sauce", "16.8", "15", "0.15", "214.2"))
@@ -2020,7 +2029,7 @@ By executing the above code example, it generates the resultant Word document as

-N> This [StartAtNewPage](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_StartAtNewPage) property is valid for group mail merge and also that the corresponding group start and group end should be present in the text body of the Word document. This [StartAtNewPage](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_StartAtNewPage) property is not valid when the group start and group end are present in the table, headers, and footers.
+N> The [StartAtNewPage](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_StartAtNewPage) property is valid only for group mail merge where the group start and group end are present in the text body of the Word document. It is not valid when the group start and group end are present inside a table, header, or footer.
## Remove mail merge settings
@@ -2066,7 +2075,7 @@ Dim document As New WordDocument("Template.docx", FormatType.Docx)
If document.MailMerge.Settings.HasData Then
document.MailMerge.Settings.RemoveData()
End If
-Saves and closes the Word document instance
+'Saves and closes the Word document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
{% endhighlight %}
@@ -2081,6 +2090,8 @@ You can change the linked **data source file path from a Word mail merge main do
The following code example shows how to change the data source file path in the template Word document.
+N> The path can be relative or absolute and should point to a file format supported by Microsoft Word for mail merge (for example, `.txt`, `.csv`, `.xls`/`.xlsx`, or `.mdb`).
+
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Change-mail-merge-data-source-path/.NET/Change-mail-merge-data-source-path/Program.cs" %}
diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md
index 3598869836..4f555a22d1 100644
--- a/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md
+++ b/Document-Processing/Word/Word-Library/NET/mail-merge/mail-merge-troubleshooting-tips.md
@@ -1,25 +1,26 @@
---
-title: Troubleshooting tips for Mail merge | DocIO | Syncfusion
+title: Troubleshooting tips for Mail Merge | DocIO | Syncfusion
description: Learn how to troubleshoot Mail Merge issues in the .NET Word (DocIO) library, including common errors.
platform: document-processing
control: DocIO
documentation: UG
---
-# Troubleshooting Mail merge Issues in .NET Word Library
+# Troubleshooting Mail Merge Issues in .NET Word Library
## Why is mail merge not working correctly in DocIO?
-Mail merge issues can arise due to incorrect merge fields, mismatched data sources, or missing fields in the template. Ensure the following:
+Mail Merge issues can arise due to incorrect merge fields, mismatched data sources, or missing fields in the template. Ensure the following:
* Merge fields (<>) are used instead of plain text.
-* **Data Source Check:** Ensure the required fields exist in the data source.
-* **Match Field Names:** Sometimes, the field names in the Word document are different from the property names in your data source class. For example, if your document has "FirstName" and "LastName", but your Employee class uses different names, mail merge will not work correctly.
+* **Data Source Check:** Ensure the required fields exist in the data source. Verify the data source column/property names against the merge field names in the Word template.
+* **Match Field Names:** Sometimes, the field names in the Word document are different from the property names in your data source class. For example, if your document has "FirstName" and "LastName", but your Employee class uses different names, Mail Merge will not work correctly.
**How to fix this:**
- * The property names in your MergeField class should be exactly the same as the merge field names in your Word document.
+ * The property names in your data source class should be exactly the same as the merge field names in your Word document.
* Field names are case-sensitive, so make sure they match exactly.
- * You can press **Alt + F9** in Microsoft Word to see the actual field codes and check if they are correct.
+
+**How to verify the merge fields:** Press **Alt + F9** in Microsoft Word to reveal the actual field codes and confirm the merge field names are correct.
**Example:**
@@ -59,7 +60,7 @@ End Class
## Why does mail merge not recognize manually typed text in Word document?
-Mail merge only works with merge fields, not manually typed placeholders. If text is entered instead of a merge field, Word treats it as plain text.
+Mail Merge only works with merge fields, not manually typed placeholders. If text is entered instead of a merge field, Word treats it as plain text.
**Solution using Microsoft Word:**
1. Navigate to Insert → Field or press Ctrl+F9.
@@ -70,8 +71,11 @@ Mail merge only works with merge fields, not manually typed placeholders. If tex
Refer to [Syncfusion® Documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-find-and-replace#find-and-replace-a-pattern-of-text-with-a-merge-field) for detailed implementation.
-## Why is nested group mail merge not functioning correctly?
+## Why is nested group Mail Merge not functioning correctly?
+
+Nested Mail Merge requires proper execution using the correct method and structure.
+* Use the appropriate overload of the [`ExecuteNestedGroup`](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) method to handle nested groups effectively. Supported overloads include:
+ * `ExecuteNestedGroup(MailMergeDataTable)` — for implicit relational data, where the child groups are nested within the parent table's data.
+ * `ExecuteNestedGroup(MailMergeDataSet, List)` — for explicit relational data, where the relations between parent and child groups are defined using command entries.
+* Ensure the data structure follows the correct hierarchy for nested groups to maintain implicit relational data. Each child group must be represented as a relation between the parent table and the child table in the data source.
-Nested mail merge requires proper execution using the correct method and structure.
-* Use the appropriate overload of the ExecuteNestedGroup method to handle nested groups effectively. Refer to the Syncfusion documentation for supported overloads.
-* Ensure the data structure follows the correct hierarchy for nested groups to maintain implicit relational data.
diff --git a/Document-Processing/Word/Word-Library/NET/mail-merge/simple-mail-merge.md b/Document-Processing/Word/Word-Library/NET/mail-merge/simple-mail-merge.md
index b0e6fec7af..ec1e3c0274 100644
--- a/Document-Processing/Word/Word-Library/NET/mail-merge/simple-mail-merge.md
+++ b/Document-Processing/Word/Word-Library/NET/mail-merge/simple-mail-merge.md
@@ -1,12 +1,12 @@
---
-title: Simple Mail merge in C# | DocIO | Syncfusion
-description: Learn how to Mail merge - replace all merge fields with data, by repeating whole document for each record in data source using the .NET Word (DocIO) library.
+title: Simple mail merge in C# | DocIO | Syncfusion
+description: Learn how to mail merge - replace all merge fields with data, by repeating whole document for each record in data source using the .NET Word (DocIO) library.
platform: document-processing
control: DocIO
documentation: UG
---
-# Simple Mail merge in Word document
+# Simple mail merge in a Word document
You can create a Word document template using Microsoft Word application or by adding merge fields in the Word document programmatically. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-mail-merge#create-word-document-template).
@@ -49,11 +49,11 @@ The following table illustrates the supported mail merge overloads for Execute m
-## Mail merge with string arrays
+## Mail Merge with string arrays
-The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides various overloads for [Execute](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_Execute_System_String___System_String___) method to perform Mail merge from various data sources. The Mail merge operation replaces the matching merge fields with the respective data.
+The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides various overloads for the [Execute](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_Execute_System_String___System_String___) method to perform a mail merge from various data sources. The mail merge operation replaces the matching merge fields with the respective data. Unmatched merge fields are left unchanged in the output document by default.
-### Create Word document template
+### Create a Word document template
The following code example shows how to create a Word template document with merge fields.
@@ -78,9 +78,10 @@ document.LastParagraph.AppendText("\nPhone: ");
document.LastParagraph.AppendField("Phone", FieldType.FieldMergeField);
document.LastParagraph.AppendText("\nCity: ");
document.LastParagraph.AppendField("City", FieldType.FieldMergeField);
-//Saves the Word document to MemoryStream
-MemoryStream stream = new MemoryStream();
-document.Save(stream, FormatType.Docx);
+//Saves the Word document to a file
+FileStream fileStream = new FileStream("Template.docx", FileMode.Create, FileAccess.ReadWrite);
+document.Save(fileStream, FormatType.Docx);
+fileStream.Dispose();
//Closes the Word document
document.Close();
{% endhighlight %}
@@ -139,8 +140,7 @@ The generated template document looks as follows.
### Execute mail merge
-The following code example shows how to perform a simple Mail merge in the generated template document with string array as data source.
-
+The following code example shows how to perform a simple mail merge in the generated template document with a string array as the data source.
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Mail-merge-with-string-arrays/.NET/Mail-merge-with-string-arrays/Program.cs" %}
@@ -191,4 +191,4 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
The resultant document looks as follows.
-
\ No newline at end of file
+
diff --git a/Document-Processing/Word/Word-Library/NET/working-with-mail-merge.md b/Document-Processing/Word/Word-Library/NET/working-with-mail-merge.md
index a756e7dde0..a25695e0c0 100644
--- a/Document-Processing/Word/Word-Library/NET/working-with-mail-merge.md
+++ b/Document-Processing/Word/Word-Library/NET/working-with-mail-merge.md
@@ -5,9 +5,9 @@ platform: document-processing
control: DocIO
documentation: UG
---
-# Working with Mail merge
+# Working with Mail merge in a Word document
-Mail merge is a process of merging data from data source to a Word template document. The [WMergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WMergeField.html) class provides support to bind template document and data source. The [WMergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WMergeField.html) instance is replaced with the actual data retrieved from data source for the given merge field name in a template document.
+Mail merge is a process of merging data from a data source into a Word template document. The [WMergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WMergeField.html) class provides support to bind template document and data source. The [WMergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WMergeField.html) instance is replaced with the actual data retrieved from the data source for the given merge field name in a template document.
## Supported data sources
@@ -16,7 +16,7 @@ The following data sources are supported by Essential® DocIO for
Data Source
|
-Examples
|
+Sample
|
@@ -98,12 +98,12 @@ The mail merge process involves three documents:
3. **Final merged document**: This resultant document is a combination of the template Word document and the data from data source.
-T> 1. You can use conditional fields ([IF](https://support.microsoft.com/en-us/office/field-codes-if-field-9f79e82f-e53b-4ff5-9d2c-ae3b22b7eb5e?ui=en-us&rs=en-us&ad=us), [Formula](https://support.microsoft.com/en-us/office/field-codes-formula-field-32d5c9de-3516-4ec3-80ed-d1fc2b5bc21d?ui=en-us&rs=en-us&ad=us)) combined with merge fields, when you require intelligent decisions in addition to simple mail merge (replace merge fields with result text). To use conditional fields, execute mail merge and then update fields in the Word document using [UpdateDocumentFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_UpdateDocumentFields) API.
-T> 2. You can replace the fields ([IF](https://support.microsoft.com/en-us/office/field-codes-if-field-9f79e82f-e53b-4ff5-9d2c-ae3b22b7eb5e?ui=en-us&rs=en-us&ad=us), [Formula](https://support.microsoft.com/en-us/office/field-codes-formula-field-32d5c9de-3516-4ec3-80ed-d1fc2b5bc21d?ui=en-us&rs=en-us&ad=us)) combined with merge fields, with its most recent result and **generates the plain Word document** by unlinking the fields. Refer to this [link](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-fields#unlink-fields) for more information.
+T> 1. You can use conditional fields ([IF](https://support.microsoft.com/en-us/office/field-codes-if-field-9f79e82f-e53b-4ff5-9d2c-ae3b22b7eb5e?ui=en-us&rs=en-us&ad=us), [Formula](https://support.microsoft.com/en-us/office/field-codes-formula-field-32d5c9de-3516-4ec3-80ed-d1fc2b5bc21d?ui=en-us&rs=en-us&ad=us)) combined with merge fields, when you require intelligent decisions in addition to simple mail merge (i.e., replacing merge fields with result text). To use conditional fields, execute mail merge and then update fields in the Word document using [UpdateDocumentFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_UpdateDocumentFields) API.
+T> 2. You can replace the fields ([IF](https://support.microsoft.com/en-us/office/field-codes-if-field-9f79e82f-e53b-4ff5-9d2c-ae3b22b7eb5e?ui=en-us&rs=en-us&ad=us), [Formula](https://support.microsoft.com/en-us/office/field-codes-formula-field-32d5c9de-3516-4ec3-80ed-d1fc2b5bc21d?ui=en-us&rs=en-us&ad=us)) combined with merge fields, with its most recent result and convert the field results to static text by unlinking the fields. Refer to this [link](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-fields#unlink-fields) for more information.
### Create Word document template
-You can create a template document with merge fields by using any Word editor application, like Microsoft Word. By using Word editor application, you can take the advantage of the visual interface to design unique layout, formatting, and more for your Word document template interactively.
+You can create a template document with merge fields by using any Word editor application, like Microsoft Word. By using a Word editor application, you can take the advantage of the visual interface to design unique layout, formatting, and more for your Word document template interactively.
The following screenshot shows how to insert a merge field in the Word document by **using the Microsoft Word.**
@@ -111,7 +111,7 @@ The following screenshot shows how to insert a merge field in the Word document
You need to add a prefix (“Image:”) to the merge field name for merging an image in the place of a merge field.
-**For example:** The merge field name should be like “Image:Photo” (<>)
+**For example:** The merge field name should be like "Image:Photo" (<>)
You can **create Word document template programmatically** by adding merge fields to the Word document using Essential® DocIO.
@@ -123,16 +123,20 @@ N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-plat
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Create-merge-field/.NET/Create-merge-field/Program.cs" %}
//Creates an instance of a WordDocument
-WordDocument document = new WordDocument();
-//Adds a section and a paragraph in the document
-document.EnsureMinimal();
-//Appends merge field to the last paragraph.
-document.LastParagraph.AppendField("FullName", FieldType.FieldMergeField);
-//Saves the Word document to MemoryStream
-MemoryStream stream = new MemoryStream();
-document.Save(stream, FormatType.Docx);
-//Closes the Word document
-document.Close();
+using (WordDocument document = new WordDocument())
+{
+ //Adds a section and a paragraph in the document
+ document.EnsureMinimal();
+ //Appends merge field to the last paragraph.
+ document.LastParagraph.AppendField("FullName", FieldType.FieldMergeField);
+ //Saves the Word document to MemoryStream
+ using (MemoryStream stream = new MemoryStream())
+ {
+ document.Save(stream, FormatType.Docx);
+ //Writes the Word document to a file
+ File.WriteAllBytes("Template.docx", stream.ToArray());
+ }
+}
{% endhighlight %}
{% highlight c# tabtitle="C# [Windows-specific]" %}
@@ -171,17 +175,21 @@ The following code example shows how to perform mail merge in above Word documen
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/DocIO-Examples/main/Mail-Merge/Getting-started-mail-merge/.NET/Getting-started-mail-merge/Program.cs" %}
//Opens the template document
-FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
-WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
-string[] fieldNames = new string[] { "FullName" };
-string[] fieldValues = new string[] { "Nancy Davolio" };
-//Performs the mail merge
-document.MailMerge.Execute(fieldNames, fieldValues);
-//Saves the Word document to MemoryStream
-MemoryStream stream = new MemoryStream();
-document.Save(stream, FormatType.Docx);
-//Closes the Word document
-document.Close();
+using (FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+{
+ WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
+ string[] fieldNames = new string[] { "FullName" };
+ string[] fieldValues = new string[] { "Nancy Davolio" };
+ //Performs the mail merge
+ document.MailMerge.Execute(fieldNames, fieldValues);
+ //Saves the Word document to MemoryStream
+ using (MemoryStream stream = new MemoryStream())
+ {
+ document.Save(stream, FormatType.Docx);
+ //Writes the Word document to a file
+ File.WriteAllBytes("Sample.docx", stream.ToArray());
+ }
+}
{% endhighlight %}
{% highlight c# tabtitle="C# [Windows-specific]" %}
@@ -222,15 +230,15 @@ The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.Do
## Performing Mail merge for a group
-You can perform Mail merge and append multiple records from data source within a specified region to a template document. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-for-group).
+You can perform Mail merge and append multiple records from the data source within a specified region to a template document. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-for-group).
-## Performing Nested Mail merge for group
+## Performing Nested Mail merge for a group
-You can perform nested Mail merge with relational or hierarchical data source and independent data tables in a template document. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-for-nested-groups).
+You can perform nested Mail merge with a relational or hierarchical data source and independent data tables in a template document. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-for-nested-groups).
## Performing Mail merge with dynamic objects
-Essential® DocIO allows you to perform Mail merge with the dynamic objects. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-for-nested-groups#mail-merge-with-dynamic-objects).
+Essential® DocIO allows you to perform Mail merge with dynamic objects. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-for-nested-groups#mail-merge-with-dynamic-objects).
## Performing Mail merge with business objects
@@ -242,9 +250,9 @@ Essential® DocIO supports performing nested Mail merge with impli
## Event support for mail merge
-The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides event support to customize the document contents and merging image data during the Mail merge process. The following events are supported by Essential® DocIO in Mail merge process:
+The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html) class provides event support to customize the document contents and merging image data during the Mail merge process. The following events are supported by Essential® DocIO in the Mail merge process:
-* [MergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeFieldEventHandler.html): Occurs when a **Mail merge field** except image Mail merge field is encountered.
+* [MergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeFieldEventHandler.html): Occurs when a **Mail merge field** except an image Mail merge field is encountered.
* [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html): Occurs when an **image Mail merge field** is encountered.
@@ -254,19 +262,19 @@ The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.Do
### MergeField event
-You can customize the merging text during Mail merge process by using the [MergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#mergefield-event).
+You can customize the merging text during the Mail merge process by using the [MergeField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#mergefield-event).
### MergeImageField event
-You can customize the merging image during Mail merge process by using the [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#mergeimagefield-event).
+You can customize the merging image during the Mail merge process by using the [MergeImageField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MergeImageFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#mergeimagefield-event).
### BeforeClearField event
-You can get the unmerged fields during Mail merge process by using the [BeforeClearField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#beforeclearfield-event).
+You can get the unmerged fields during the Mail merge process by using the [BeforeClearField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#beforeclearfield-event).
### BeforeClearGroupField event
-You can get the unmerged groups during Mail merge process by using the [BeforeClearGroupField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearGroupFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#beforecleargroupfield-event).
+You can get the unmerged groups during the Mail merge process by using the [BeforeClearGroupField](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.BeforeClearGroupFieldEventHandler.html) event. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-events#beforecleargroupfield-event).
## Mail merge options
@@ -274,7 +282,7 @@ The [MailMerge](https://help.syncfusion.com/cr/document-processing/Syncfusion.Do
### Field mapping
-You can automatically map the merge field names with data source column names during Mail merge process. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-options#field-mapping).
+You can automatically map the merge field names with the data source column names during the Mail merge process. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-options#field-mapping).
### Retrieving the merge field names
@@ -282,11 +290,11 @@ You can retrieve the merge field names and also merge field group names in the W
### Removing empty paragraphs
-You can remove the empty paragraphs when the paragraph has a merge field item without any data during Mail merge process. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-options#remove-empty-paragraphs).
+You can remove the empty paragraphs when the paragraph has a merge field item without any data during the Mail merge process. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-options#remove-empty-paragraphs).
### Removing empty merge fields
-You can remove or keep the unmerged merge fields in the output document based on the [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property on each mail merge execution. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-options#remove-empty-merge-fields).
+You can remove or keep the unmerged merge fields in the output document based on the [ClearFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.DocIO.DLS.MailMerge.html#Syncfusion_DocIO_DLS_MailMerge_ClearFields) property on each mail merge execution. The default value of `ClearFields` is `true`, which removes unmerged merge fields. For further information, click [here](https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-options#remove-empty-merge-fields).
### Restart numbering in lists
|