Skip to content

Commit ec3c324

Browse files
author
Dharani Thangarasu
committed
Merge branch 'WF-56078_UG_Documentation_working_with_DOM_elements' of https://gitlab.syncfusion.com/content/java-file-format-docs into WF-56078_UG_Documentation_working_with_DOM_elements
2 parents 9826c43 + 6efacb7 commit ec3c324

File tree

3 files changed

+1
-139
lines changed

3 files changed

+1
-139
lines changed

java-file-formats/word-library/mail-merge/mail-merge-events.md

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ The `MailMerge` class provides event support to customize the document contents
1414

1515
* `MergeImageField`- occurs when an **image Mail merge field** is encountered.
1616

17-
* `BeforeClearField`- occurs when an **unmerged field** is encountered.
18-
1917
* `BeforeClearGroupField`- occurs when an **unmerged group field** is encountered.
2018

2119
## MergeField Event
@@ -174,115 +172,6 @@ private void mergeField_ProductImage(Object sender, MergeImageFieldEventArgs arg
174172

175173
{% endtabs %}
176174

177-
## BeforeClearField Event
178-
179-
You can get the unmerged fields in a Word document during mail merge process using the `BeforeClearField` Event.
180-
181-
The following code example shows how to use the `BeforeClearField` event during Mail merge process.
182-
183-
{% tabs %}
184-
185-
{% highlight JAVA %}
186-
//Opens the template document.
187-
WordDocument document = new WordDocument("Template.docx",FormatType.Docx);
188-
//Sets a value indicating whether to remove empty mail merge fields from a document.
189-
document.getMailMerge().setClearFields(false);
190-
//Uses the mail merge event to clear the unmerged field while perform mail merge execution.
191-
document.getMailMerge().BeforeClearField.add("beforeClearFieldEvent", new BeforeClearFieldEventHandler() {
192-
ListSupport<BeforeClearFieldEventHandler> delegateList = new ListSupport<BeforeClearFieldEventHandler>(
193-
BeforeClearFieldEventHandler.class);
194-
//Represents event handling for BeforeClearFieldEventHandler.
195-
public void invoke(Object sender, BeforeClearFieldEventArgs args) throws Exception {
196-
beforeClearFieldEvent(sender, args);
197-
}
198-
//Represents the method that handles BeforeClearField event.
199-
public void dynamicInvoke(Object... args) throws Exception {
200-
beforeClearFieldEvent((Object) args[0], (BeforeClearFieldEventArgs) args[1]);
201-
}
202-
//Represents the method that handles BeforeClearField event to add collection item.
203-
public void add(BeforeClearFieldEventHandler delegate) throws Exception {
204-
if (delegate != null)
205-
delegateList.add(delegate);
206-
}
207-
//Represents the method that handles BeforeClearField event to remove collection item.
208-
public void remove(BeforeClearFieldEventHandler delegate) throws Exception {
209-
if (delegate != null)
210-
delegateList.remove(delegate);
211-
}
212-
});
213-
//Execute group mail merge.
214-
document.getMailMerge().executeGroup(getDataTable());
215-
//Saves the Word document.
216-
document.save("Samples.docx", FormatType.Docx);
217-
//Closes the Word document.
218-
document.close();
219-
{% endhighlight %}
220-
221-
{% endtabs %}
222-
223-
The following code example shows how to bind the data to unmerged fields during Mail merge process by using BeforeClearFieldEventHandler.
224-
225-
{% tabs %}
226-
227-
{% highlight JAVA %}
228-
private void beforeClearFieldEvent (Object sender, BeforeClearFieldEventArgs args) throws Exception
229-
{
230-
if (args.getHasMappedFieldInDataSource())
231-
{
232-
//To check whether the mapped field has null value.
233-
if ((args.getFieldValue())==null) //|| args.getFieldValue().equals(DBNull.Value))
234-
{
235-
//Gets the unmerged field name.
236-
String unmergedFieldName = args.getFieldName();
237-
String ownerGroup = args.getGroupName();
238-
//Sets error message for unmerged fields.
239-
args.setFieldValue("Error! The value of MergeField " + unmergedFieldName + " of owner group " + ownerGroup + " is defined as Null in the data source.");
240-
}
241-
else
242-
//If field value is empty, you can set whether the unmerged merge field can be clear or not.
243-
args.setClearField(true);
244-
}
245-
else
246-
{
247-
String unmergedFieldName = args.getFieldName();
248-
//Sets error message for unmerged fields, which is not found in data source.
249-
args.setFieldValue("Error! The value of MergeField " + unmergedFieldName + " is not found in the data source.");
250-
}
251-
}
252-
{% endhighlight %}
253-
254-
{% endtabs %}
255-
256-
The following code example shows getDataTable method which is used to get data for mail merge.
257-
258-
{% tabs %}
259-
260-
{% highlight JAVA %}
261-
private DataTableSupport getDataTable() throws Exception
262-
{
263-
//Create an instance of DataTable.
264-
DataTableSupport dataTable = new DataTableSupport("Employee");
265-
//Add columns.
266-
dataTable.getColumns().add("EmployeeId");
267-
dataTable.getColumns().add("City");
268-
//Add records.
269-
DataRowSupport row;
270-
row = dataTable.newRow();
271-
row.set("EmployeeId", "1001");
272-
row.set("City", null);
273-
dataTable.getRows().add(row);
274-
row = dataTable.newRow();
275-
row.set("EmployeeId", "1002");
276-
row.set("City", "");
277-
dataTable.getRows().add(row);
278-
row = dataTable.newRow();
279-
row.set("EmployeeId", "1003");
280-
row.set("City", "London");
281-
dataTable.getRows().add(row);
282-
return dataTable;
283-
}
284-
{% endhighlight %}
285-
{% endtabs %}
286175

287176
## BeforeClearGroupField Event
288177

java-file-formats/word-library/mail-merge/mail-merge-options.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -556,24 +556,3 @@ document.close();
556556
{% endhighlight %}
557557

558558
{% endtabs %}
559-
560-
## Change mail merge data source path
561-
562-
You can change the linked **data source file path from a Word mail merge main document**, which is used for mail merge process by Microsoft Word application.
563-
564-
The following code example shows how to change the data source file path in the template Word document.
565-
566-
{% tabs %}
567-
568-
{% highlight JAVA %}
569-
//Opens the template document.
570-
WordDocument document = new WordDocument("Template.docx", FormatType.Docx);
571-
//Change the data source file path.
572-
document.getMailMerge().getSettings().setDataSource("Document.txt");
573-
//Saves the Word document.
574-
document.save("Sample.docx", FormatType.Docx);
575-
//Closes the Word document.
576-
document.close();
577-
{% endhighlight %}
578-
579-
{% endtabs %}

java-file-formats/word-library/working-with-mail-merge.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
title: Working with Mail merge | Syncfusion
33
description: This section illustrates about Mail merge Word document to create reports (letters, envelopes, labels, invoice, payroll) without MS Word or Office interop.
44
platform: java-file-formats
@@ -111,8 +111,6 @@ The `MailMerge` class provides event support to customize the document contents
111111

112112
* `MergeImageField`: Occurs when an **image Mail merge field** is encountered.
113113

114-
* `BeforeClearField`: Occurs when an **unmerged field** is encountered.
115-
116114
* `BeforeClearGroupField`: Occurs when an **unmerged group field** is encountered.
117115

118116
### MergeField event
@@ -123,10 +121,6 @@ You can customize the merging text during Mail merge process by using the `Merge
123121

124122
You can customize the merging image during Mail merge process by using the `MergeImageField` event. For further information, click [here](https://help.syncfusion.com/java-file-formats/word-library/mail-merge/mail-merge-events#mergeimagefield-event).
125123

126-
### BeforeClearField event
127-
128-
You can get the unmerged fields during Mail merge process by using the `BeforeClearField` event. For further information, click [here](https://help.syncfusion.com/java-file-formats/word-library/mail-merge/mail-merge-events#beforeclearfield-event).
129-
130124
### BeforeClearGroupField event
131125

132126
You can get the unmerged groups during Mail merge process by using the `BeforeClearGroupField` event. For further information, click [here](https://help.syncfusion.com/java-file-formats/word-library/mail-merge/mail-merge-events#beforecleargroupfield-event).

0 commit comments

Comments
 (0)