MailMergeClearOptions Enumeration |
Specifies options that determine what items are removed during mail merge.
Namespace: SautinSoft.Document.MailMergingAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.7.18
Syntax [FlagsAttribute]
public enum MailMergeClearOptions
<FlagsAttribute>
Public Enumeration MailMergeClearOptions
Members Member name | Value | Description |
---|
None | 0 |
Do not remove unused fields nor empty ranges nor empty paragraphs.
|
RemoveUnusedFields | 1 |
Remove fields for which no data has been found in the mail merge data source.
|
RemoveEmptyRanges | 2 |
Remove ranges into which no field has been merged.
|
RemoveEmptyParagraphs | 4 |
Remove paragraphs which contained merge fields but none of them has been merged.
|
RemoveEmptyTableRows | 8 |
Remove table rows which contained merge fields but none of them has been merged.
|
Example See Developer Guide: Shows how use ClearOptions - remove specific elements if no data has been imported into them
Shows how use ClearOptions - remove specific elements if no data has been imported into them in C#
using SautinSoft.Document;
using SautinSoft.Document.MailMerging;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
MailMergeWithClearOptions();
}
static void MailMergeWithClearOptions()
{
DocumentCore document = DocumentCore.Load(@"..\..\..\MailMergeClearOptions.docx");
var dataSource1 = new
{
Field2 = "Some text"
};
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveUnusedFields;
document.MailMerge.Execute(dataSource1, "Example1");
var dataSource2 = new
{
Field1 = string.Empty,
Field2 = "Some text"
};
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveEmptyParagraphs;
document.MailMerge.Execute(dataSource2, "Example2");
var dataSource3 = new
{
Field1 = "Some text 1",
Field2 = (string)null,
Field3 = "Some text 3",
};
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveEmptyTableRows;
document.MailMerge.Execute(dataSource3, "Example3");
var dataSource4 = new
{
TotalRecords = 2,
Records = new object[]
{
new
{
Record = 1,
Text = "Some text 1"
},
new
{
Record = (object)null,
Text = string.Empty
},
new
{
Record = 3,
Text = "Some text 3"
},
}
};
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveEmptyRanges;
document.MailMerge.Execute(dataSource4, "Example4");
string resultPath = "ClearOptions.docx";
document.Save(resultPath);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultPath) { UseShellExecute = true });
}
}
}
Shows how use ClearOptions - remove specific elements if no data has been imported into them in VB.Net
Option Infer On
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports SautinSoft.Document
Imports SautinSoft.Document.MailMerging
Namespace Sample
Friend Class Program
Shared Sub Main(ByVal args() As String)
MailMergeWithClearOptions()
End Sub
Private Shared Sub MailMergeWithClearOptions()
Dim document As DocumentCore = DocumentCore.Load("..\..\..\MailMergeClearOptions.docx")
Dim dataSource1 = New With {Key .Field2 = "Some text"}
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveUnusedFields
document.MailMerge.Execute(dataSource1, "Example1")
Dim dataSource2 = New With {
Key .Field1 = String.Empty,
Key .Field2 = "Some text"
}
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveEmptyParagraphs
document.MailMerge.Execute(dataSource2, "Example2")
Dim dataSource3 = New With {
Key .Field1 = "Some text 1",
Key .Field2 = DirectCast(Nothing, String),
Key .Field3 = "Some text 3"
}
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveEmptyTableRows
document.MailMerge.Execute(dataSource3, "Example3")
Dim dataSource4 = New With {
Key .TotalRecords = 2,
Key .Records = New Object() {
New With {
Key .Record = 1,
Key .Text = "Some text 1"
},
New With {
Key .Record = DirectCast(Nothing, Object),
Key .Text = String.Empty
},
New With {
Key .Record = 3,
Key .Text = "Some text 3"
}
}
}
document.MailMerge.ClearOptions = MailMergeClearOptions.RemoveEmptyRanges
document.MailMerge.Execute(dataSource4, "Example4")
Dim resultPath As String = "ClearOptions.docx"
document.Save(resultPath)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultPath) With {.UseShellExecute = True})
End Sub
End Class
End Namespace
See Also