public class FieldSkipIf extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Compares the values designated by the expressions getLeftExpression() / setLeftExpression(java.lang.String) and getRightExpression() / setRightExpression(java.lang.String) in comparison using the operator designated by getComparisonOperator() / setComparisonOperator(java.lang.String). If the comparison is true, SKIPIF cancels the current merge document, moves to the next data record in the data source, and starts a new merge document. If the comparison is false, the current merge document is continued.
Examples:
Shows how to skip pages in a mail merge using the SKIPIF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a SKIPIF field. If the current row of a mail merge operation fulfills the condition
// which the expressions of this field state, then the mail merge operation aborts the current row,
// discards the current merge document, and then immediately moves to the next row to begin the next merge document.
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
// Move the builder to the SKIPIF field's separator so we can place a MERGEFIELD inside the SKIPIF field.
builder.moveTo(fieldSkipIf.getSeparator());
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Department");
// The MERGEFIELD refers to the "Department" column in our data table. If a row from that table
// has a value of "HR" in its "Department" column, then this row will fulfill the condition.
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("HR");
// Add content to our document, create the data source, and execute the mail merge.
builder.moveToDocumentEnd();
builder.write("Dear ");
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(", ");
// This table has three rows, and one of them fulfills the condition of our SKIPIF field.
// The mail merge will produce two pages.
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getColumns().add("Department");
table.getRows().add("John Doe", "Sales");
table.getRows().add("Jane Doe", "Accounting");
table.getRows().add("John Cardholder", "HR");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.SKIPIF.docx");
Shows how to use MERGEREC and MERGESEQ fields to the number and count mail merge records in a mail merge's output documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Dear ");
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(",");
// A MERGEREC field will print the row number of the data being merged in every merge output document.
builder.write("\nRow number of record in data source: ");
FieldMergeRec fieldMergeRec = (FieldMergeRec) builder.insertField(FieldType.FIELD_MERGE_REC, true);
Assert.assertEquals(fieldMergeRec.getFieldCode(), " MERGEREC ");
// A MERGESEQ field will count the number of successful merges and print the current value on each respective page.
// If a mail merge skips no rows and invokes no SKIP/SKIPIF/NEXT/NEXTIF fields, then all merges are successful.
// The MERGESEQ and MERGEREC fields will display the same results of their mail merge was successful.
builder.write("\nSuccessful merge number: ");
FieldMergeSeq fieldMergeSeq = (FieldMergeSeq) builder.insertField(FieldType.FIELD_MERGE_SEQ, true);
Assert.assertEquals(fieldMergeSeq.getFieldCode(), " MERGESEQ ");
// Insert a SKIPIF field, which will skip a merge if the name is "John Doe".
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
builder.moveTo(fieldSkipIf.getSeparator());
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("John Doe");
// Create a data source with 3 rows, one of them having "John Doe" as a value for the "Name" column.
// Since a SKIPIF field will be triggered once by that value, the output of our mail merge will have 2 pages instead of 3.
// On page 1, the MERGESEQ and MERGEREC fields will both display "1".
// On page 2, the MERGEREC field will display "3" and the MERGESEQ field will display "2".
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getRows().add("Jane Doe");
table.getRows().add("John Doe");
table.getRows().add("Joe Bloggs");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.MERGEREC.MERGESEQ.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getComparisonOperator()
Gets the comparison operator.
|
java.lang.String |
getLeftExpression()
Gets the left part of the comparison expression.
|
java.lang.String |
getRightExpression()
Gets the right part of the comparison expression.
|
void |
setComparisonOperator(java.lang.String value)
Sets the comparison operator.
|
void |
setLeftExpression(java.lang.String value)
Sets the left part of the comparison expression.
|
void |
setRightExpression(java.lang.String value)
Sets the right part of the comparison expression.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getLeftExpression()
Examples:
Shows how to skip pages in a mail merge using the SKIPIF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a SKIPIF field. If the current row of a mail merge operation fulfills the condition
// which the expressions of this field state, then the mail merge operation aborts the current row,
// discards the current merge document, and then immediately moves to the next row to begin the next merge document.
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
// Move the builder to the SKIPIF field's separator so we can place a MERGEFIELD inside the SKIPIF field.
builder.moveTo(fieldSkipIf.getSeparator());
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Department");
// The MERGEFIELD refers to the "Department" column in our data table. If a row from that table
// has a value of "HR" in its "Department" column, then this row will fulfill the condition.
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("HR");
// Add content to our document, create the data source, and execute the mail merge.
builder.moveToDocumentEnd();
builder.write("Dear ");
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(", ");
// This table has three rows, and one of them fulfills the condition of our SKIPIF field.
// The mail merge will produce two pages.
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getColumns().add("Department");
table.getRows().add("John Doe", "Sales");
table.getRows().add("Jane Doe", "Accounting");
table.getRows().add("John Cardholder", "HR");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.SKIPIF.docx");
Shows how to use MERGEREC and MERGESEQ fields to the number and count mail merge records in a mail merge's output documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Dear ");
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(",");
// A MERGEREC field will print the row number of the data being merged in every merge output document.
builder.write("\nRow number of record in data source: ");
FieldMergeRec fieldMergeRec = (FieldMergeRec) builder.insertField(FieldType.FIELD_MERGE_REC, true);
Assert.assertEquals(fieldMergeRec.getFieldCode(), " MERGEREC ");
// A MERGESEQ field will count the number of successful merges and print the current value on each respective page.
// If a mail merge skips no rows and invokes no SKIP/SKIPIF/NEXT/NEXTIF fields, then all merges are successful.
// The MERGESEQ and MERGEREC fields will display the same results of their mail merge was successful.
builder.write("\nSuccessful merge number: ");
FieldMergeSeq fieldMergeSeq = (FieldMergeSeq) builder.insertField(FieldType.FIELD_MERGE_SEQ, true);
Assert.assertEquals(fieldMergeSeq.getFieldCode(), " MERGESEQ ");
// Insert a SKIPIF field, which will skip a merge if the name is "John Doe".
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
builder.moveTo(fieldSkipIf.getSeparator());
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("John Doe");
// Create a data source with 3 rows, one of them having "John Doe" as a value for the "Name" column.
// Since a SKIPIF field will be triggered once by that value, the output of our mail merge will have 2 pages instead of 3.
// On page 1, the MERGESEQ and MERGEREC fields will both display "1".
// On page 2, the MERGEREC field will display "3" and the MERGESEQ field will display "2".
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getRows().add("Jane Doe");
table.getRows().add("John Doe");
table.getRows().add("Joe Bloggs");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.MERGEREC.MERGESEQ.docx");
public void setLeftExpression(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to skip pages in a mail merge using the SKIPIF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a SKIPIF field. If the current row of a mail merge operation fulfills the condition
// which the expressions of this field state, then the mail merge operation aborts the current row,
// discards the current merge document, and then immediately moves to the next row to begin the next merge document.
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
// Move the builder to the SKIPIF field's separator so we can place a MERGEFIELD inside the SKIPIF field.
builder.moveTo(fieldSkipIf.getSeparator());
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Department");
// The MERGEFIELD refers to the "Department" column in our data table. If a row from that table
// has a value of "HR" in its "Department" column, then this row will fulfill the condition.
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("HR");
// Add content to our document, create the data source, and execute the mail merge.
builder.moveToDocumentEnd();
builder.write("Dear ");
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(", ");
// This table has three rows, and one of them fulfills the condition of our SKIPIF field.
// The mail merge will produce two pages.
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getColumns().add("Department");
table.getRows().add("John Doe", "Sales");
table.getRows().add("Jane Doe", "Accounting");
table.getRows().add("John Cardholder", "HR");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.SKIPIF.docx");
Shows how to use MERGEREC and MERGESEQ fields to the number and count mail merge records in a mail merge's output documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Dear ");
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(",");
// A MERGEREC field will print the row number of the data being merged in every merge output document.
builder.write("\nRow number of record in data source: ");
FieldMergeRec fieldMergeRec = (FieldMergeRec) builder.insertField(FieldType.FIELD_MERGE_REC, true);
Assert.assertEquals(fieldMergeRec.getFieldCode(), " MERGEREC ");
// A MERGESEQ field will count the number of successful merges and print the current value on each respective page.
// If a mail merge skips no rows and invokes no SKIP/SKIPIF/NEXT/NEXTIF fields, then all merges are successful.
// The MERGESEQ and MERGEREC fields will display the same results of their mail merge was successful.
builder.write("\nSuccessful merge number: ");
FieldMergeSeq fieldMergeSeq = (FieldMergeSeq) builder.insertField(FieldType.FIELD_MERGE_SEQ, true);
Assert.assertEquals(fieldMergeSeq.getFieldCode(), " MERGESEQ ");
// Insert a SKIPIF field, which will skip a merge if the name is "John Doe".
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
builder.moveTo(fieldSkipIf.getSeparator());
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("John Doe");
// Create a data source with 3 rows, one of them having "John Doe" as a value for the "Name" column.
// Since a SKIPIF field will be triggered once by that value, the output of our mail merge will have 2 pages instead of 3.
// On page 1, the MERGESEQ and MERGEREC fields will both display "1".
// On page 2, the MERGEREC field will display "3" and the MERGESEQ field will display "2".
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getRows().add("Jane Doe");
table.getRows().add("John Doe");
table.getRows().add("Joe Bloggs");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.MERGEREC.MERGESEQ.docx");
value - The left part of the comparison expression.java.lang.Exceptionpublic java.lang.String getComparisonOperator()
Examples:
Shows how to skip pages in a mail merge using the SKIPIF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a SKIPIF field. If the current row of a mail merge operation fulfills the condition
// which the expressions of this field state, then the mail merge operation aborts the current row,
// discards the current merge document, and then immediately moves to the next row to begin the next merge document.
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
// Move the builder to the SKIPIF field's separator so we can place a MERGEFIELD inside the SKIPIF field.
builder.moveTo(fieldSkipIf.getSeparator());
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Department");
// The MERGEFIELD refers to the "Department" column in our data table. If a row from that table
// has a value of "HR" in its "Department" column, then this row will fulfill the condition.
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("HR");
// Add content to our document, create the data source, and execute the mail merge.
builder.moveToDocumentEnd();
builder.write("Dear ");
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(", ");
// This table has three rows, and one of them fulfills the condition of our SKIPIF field.
// The mail merge will produce two pages.
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getColumns().add("Department");
table.getRows().add("John Doe", "Sales");
table.getRows().add("Jane Doe", "Accounting");
table.getRows().add("John Cardholder", "HR");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.SKIPIF.docx");
Shows how to use MERGEREC and MERGESEQ fields to the number and count mail merge records in a mail merge's output documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Dear ");
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(",");
// A MERGEREC field will print the row number of the data being merged in every merge output document.
builder.write("\nRow number of record in data source: ");
FieldMergeRec fieldMergeRec = (FieldMergeRec) builder.insertField(FieldType.FIELD_MERGE_REC, true);
Assert.assertEquals(fieldMergeRec.getFieldCode(), " MERGEREC ");
// A MERGESEQ field will count the number of successful merges and print the current value on each respective page.
// If a mail merge skips no rows and invokes no SKIP/SKIPIF/NEXT/NEXTIF fields, then all merges are successful.
// The MERGESEQ and MERGEREC fields will display the same results of their mail merge was successful.
builder.write("\nSuccessful merge number: ");
FieldMergeSeq fieldMergeSeq = (FieldMergeSeq) builder.insertField(FieldType.FIELD_MERGE_SEQ, true);
Assert.assertEquals(fieldMergeSeq.getFieldCode(), " MERGESEQ ");
// Insert a SKIPIF field, which will skip a merge if the name is "John Doe".
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
builder.moveTo(fieldSkipIf.getSeparator());
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("John Doe");
// Create a data source with 3 rows, one of them having "John Doe" as a value for the "Name" column.
// Since a SKIPIF field will be triggered once by that value, the output of our mail merge will have 2 pages instead of 3.
// On page 1, the MERGESEQ and MERGEREC fields will both display "1".
// On page 2, the MERGEREC field will display "3" and the MERGESEQ field will display "2".
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getRows().add("Jane Doe");
table.getRows().add("John Doe");
table.getRows().add("Joe Bloggs");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.MERGEREC.MERGESEQ.docx");
public void setComparisonOperator(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to skip pages in a mail merge using the SKIPIF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a SKIPIF field. If the current row of a mail merge operation fulfills the condition
// which the expressions of this field state, then the mail merge operation aborts the current row,
// discards the current merge document, and then immediately moves to the next row to begin the next merge document.
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
// Move the builder to the SKIPIF field's separator so we can place a MERGEFIELD inside the SKIPIF field.
builder.moveTo(fieldSkipIf.getSeparator());
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Department");
// The MERGEFIELD refers to the "Department" column in our data table. If a row from that table
// has a value of "HR" in its "Department" column, then this row will fulfill the condition.
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("HR");
// Add content to our document, create the data source, and execute the mail merge.
builder.moveToDocumentEnd();
builder.write("Dear ");
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(", ");
// This table has three rows, and one of them fulfills the condition of our SKIPIF field.
// The mail merge will produce two pages.
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getColumns().add("Department");
table.getRows().add("John Doe", "Sales");
table.getRows().add("Jane Doe", "Accounting");
table.getRows().add("John Cardholder", "HR");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.SKIPIF.docx");
Shows how to use MERGEREC and MERGESEQ fields to the number and count mail merge records in a mail merge's output documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Dear ");
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(",");
// A MERGEREC field will print the row number of the data being merged in every merge output document.
builder.write("\nRow number of record in data source: ");
FieldMergeRec fieldMergeRec = (FieldMergeRec) builder.insertField(FieldType.FIELD_MERGE_REC, true);
Assert.assertEquals(fieldMergeRec.getFieldCode(), " MERGEREC ");
// A MERGESEQ field will count the number of successful merges and print the current value on each respective page.
// If a mail merge skips no rows and invokes no SKIP/SKIPIF/NEXT/NEXTIF fields, then all merges are successful.
// The MERGESEQ and MERGEREC fields will display the same results of their mail merge was successful.
builder.write("\nSuccessful merge number: ");
FieldMergeSeq fieldMergeSeq = (FieldMergeSeq) builder.insertField(FieldType.FIELD_MERGE_SEQ, true);
Assert.assertEquals(fieldMergeSeq.getFieldCode(), " MERGESEQ ");
// Insert a SKIPIF field, which will skip a merge if the name is "John Doe".
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
builder.moveTo(fieldSkipIf.getSeparator());
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("John Doe");
// Create a data source with 3 rows, one of them having "John Doe" as a value for the "Name" column.
// Since a SKIPIF field will be triggered once by that value, the output of our mail merge will have 2 pages instead of 3.
// On page 1, the MERGESEQ and MERGEREC fields will both display "1".
// On page 2, the MERGEREC field will display "3" and the MERGESEQ field will display "2".
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getRows().add("Jane Doe");
table.getRows().add("John Doe");
table.getRows().add("Joe Bloggs");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.MERGEREC.MERGESEQ.docx");
value - The comparison operator.java.lang.Exceptionpublic java.lang.String getRightExpression()
Examples:
Shows how to skip pages in a mail merge using the SKIPIF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a SKIPIF field. If the current row of a mail merge operation fulfills the condition
// which the expressions of this field state, then the mail merge operation aborts the current row,
// discards the current merge document, and then immediately moves to the next row to begin the next merge document.
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
// Move the builder to the SKIPIF field's separator so we can place a MERGEFIELD inside the SKIPIF field.
builder.moveTo(fieldSkipIf.getSeparator());
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Department");
// The MERGEFIELD refers to the "Department" column in our data table. If a row from that table
// has a value of "HR" in its "Department" column, then this row will fulfill the condition.
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("HR");
// Add content to our document, create the data source, and execute the mail merge.
builder.moveToDocumentEnd();
builder.write("Dear ");
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(", ");
// This table has three rows, and one of them fulfills the condition of our SKIPIF field.
// The mail merge will produce two pages.
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getColumns().add("Department");
table.getRows().add("John Doe", "Sales");
table.getRows().add("Jane Doe", "Accounting");
table.getRows().add("John Cardholder", "HR");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.SKIPIF.docx");
Shows how to use MERGEREC and MERGESEQ fields to the number and count mail merge records in a mail merge's output documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Dear ");
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(",");
// A MERGEREC field will print the row number of the data being merged in every merge output document.
builder.write("\nRow number of record in data source: ");
FieldMergeRec fieldMergeRec = (FieldMergeRec) builder.insertField(FieldType.FIELD_MERGE_REC, true);
Assert.assertEquals(fieldMergeRec.getFieldCode(), " MERGEREC ");
// A MERGESEQ field will count the number of successful merges and print the current value on each respective page.
// If a mail merge skips no rows and invokes no SKIP/SKIPIF/NEXT/NEXTIF fields, then all merges are successful.
// The MERGESEQ and MERGEREC fields will display the same results of their mail merge was successful.
builder.write("\nSuccessful merge number: ");
FieldMergeSeq fieldMergeSeq = (FieldMergeSeq) builder.insertField(FieldType.FIELD_MERGE_SEQ, true);
Assert.assertEquals(fieldMergeSeq.getFieldCode(), " MERGESEQ ");
// Insert a SKIPIF field, which will skip a merge if the name is "John Doe".
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
builder.moveTo(fieldSkipIf.getSeparator());
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("John Doe");
// Create a data source with 3 rows, one of them having "John Doe" as a value for the "Name" column.
// Since a SKIPIF field will be triggered once by that value, the output of our mail merge will have 2 pages instead of 3.
// On page 1, the MERGESEQ and MERGEREC fields will both display "1".
// On page 2, the MERGEREC field will display "3" and the MERGESEQ field will display "2".
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getRows().add("Jane Doe");
table.getRows().add("John Doe");
table.getRows().add("Joe Bloggs");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.MERGEREC.MERGESEQ.docx");
public void setRightExpression(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to skip pages in a mail merge using the SKIPIF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a SKIPIF field. If the current row of a mail merge operation fulfills the condition
// which the expressions of this field state, then the mail merge operation aborts the current row,
// discards the current merge document, and then immediately moves to the next row to begin the next merge document.
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
// Move the builder to the SKIPIF field's separator so we can place a MERGEFIELD inside the SKIPIF field.
builder.moveTo(fieldSkipIf.getSeparator());
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Department");
// The MERGEFIELD refers to the "Department" column in our data table. If a row from that table
// has a value of "HR" in its "Department" column, then this row will fulfill the condition.
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("HR");
// Add content to our document, create the data source, and execute the mail merge.
builder.moveToDocumentEnd();
builder.write("Dear ");
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(", ");
// This table has three rows, and one of them fulfills the condition of our SKIPIF field.
// The mail merge will produce two pages.
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getColumns().add("Department");
table.getRows().add("John Doe", "Sales");
table.getRows().add("Jane Doe", "Accounting");
table.getRows().add("John Cardholder", "HR");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.SKIPIF.docx");
Shows how to use MERGEREC and MERGESEQ fields to the number and count mail merge records in a mail merge's output documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Dear ");
FieldMergeField fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
builder.writeln(",");
// A MERGEREC field will print the row number of the data being merged in every merge output document.
builder.write("\nRow number of record in data source: ");
FieldMergeRec fieldMergeRec = (FieldMergeRec) builder.insertField(FieldType.FIELD_MERGE_REC, true);
Assert.assertEquals(fieldMergeRec.getFieldCode(), " MERGEREC ");
// A MERGESEQ field will count the number of successful merges and print the current value on each respective page.
// If a mail merge skips no rows and invokes no SKIP/SKIPIF/NEXT/NEXTIF fields, then all merges are successful.
// The MERGESEQ and MERGEREC fields will display the same results of their mail merge was successful.
builder.write("\nSuccessful merge number: ");
FieldMergeSeq fieldMergeSeq = (FieldMergeSeq) builder.insertField(FieldType.FIELD_MERGE_SEQ, true);
Assert.assertEquals(fieldMergeSeq.getFieldCode(), " MERGESEQ ");
// Insert a SKIPIF field, which will skip a merge if the name is "John Doe".
FieldSkipIf fieldSkipIf = (FieldSkipIf) builder.insertField(FieldType.FIELD_SKIP_IF, true);
builder.moveTo(fieldSkipIf.getSeparator());
fieldMergeField = (FieldMergeField) builder.insertField(FieldType.FIELD_MERGE_FIELD, true);
fieldMergeField.setFieldName("Name");
fieldSkipIf.setLeftExpression("=");
fieldSkipIf.setRightExpression("John Doe");
// Create a data source with 3 rows, one of them having "John Doe" as a value for the "Name" column.
// Since a SKIPIF field will be triggered once by that value, the output of our mail merge will have 2 pages instead of 3.
// On page 1, the MERGESEQ and MERGEREC fields will both display "1".
// On page 2, the MERGEREC field will display "3" and the MERGESEQ field will display "2".
DataTable table = new DataTable("Employees");
table.getColumns().add("Name");
table.getRows().add("Jane Doe");
table.getRows().add("John Doe");
table.getRows().add("Joe Bloggs");
doc.getMailMerge().execute(table);
doc.save(getArtifactsDir() + "Field.MERGEREC.MERGESEQ.docx");
value - The right part of the comparison expression.java.lang.Exception