public class FieldGreetingLine extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Inserts a mail merge greeting line.
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getAlternateText()
Gets the text to include in the field if the name is blank.
|
java.lang.String[] |
getFieldNames()
Returns a collection of mail merge field names used by the field.
|
java.lang.String |
getLanguageId()
Gets the language id used to format the name.
|
java.lang.String |
getMergeFormat() |
java.lang.String |
getNameFormat()
Gets the format of the name included in the field.
|
int |
getSwitchType(java.lang.String switchName) |
Document |
iFormattableMergeField_FetchDocument() |
void |
setAlternateText(java.lang.String value)
Sets the text to include in the field if the name is blank.
|
void |
setLanguageId(java.lang.String value)
Sets the language id used to format the name.
|
void |
setNameFormat(java.lang.String value)
Sets the format of the name included in the field.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getAlternateText()
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
public void setAlternateText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
value - The text to include in the field if the name is blank.java.lang.Exceptionpublic java.lang.String getNameFormat()
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
public void setNameFormat(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
value - The format of the name included in the field.java.lang.Exceptionpublic java.lang.String getLanguageId()
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
public void setLanguageId(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
value - The language id used to format the name.java.lang.Exceptionpublic java.lang.String[] getFieldNames()
throws java.lang.Exception
Examples:
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a generic greeting using a GREETINGLINE field, and some text after it.
FieldGreetingLine field = (FieldGreetingLine) builder.insertField(FieldType.FIELD_GREETING_LINE, true);
builder.writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");
// A GREETINGLINE field accepts values from a data source during a mail merge, like a MERGEFIELD.
// It can also format how the source's data is written in its place once the mail merge is complete.
// The field names collection corresponds to the columns from the data source
// that the field will take values from.
Assert.assertEquals(0, field.getFieldNames().length);
// To populate that array, we need to specify a format for our greeting line.
field.setNameFormat("<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ");
// Now, our field will accept values from these two columns in the data source.
Assert.assertEquals("Courtesy Title", field.getFieldNames()[0]);
Assert.assertEquals("Last Name", field.getFieldNames()[1]);
Assert.assertEquals(2, field.getFieldNames().length);
// This string will cover any cases where the data table data is invalid
// by substituting the malformed name with a string.
field.setAlternateText("Sir or Madam");
// Set a locale to format the result.
field.setLanguageId("1033");
Assert.assertEquals(" GREETINGLINE \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033",
field.getFieldCode());
// Create a data table with columns whose names match elements
// from the field's field names collection, and then carry out the mail merge.
DataTable table = new DataTable("Employees");
table.getColumns().add("Courtesy Title");
table.getColumns().add("First Name");
table.getColumns().add("Last Name");
table.getRows().add("Mr.", "John", "Doe");
table.getRows().add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text.
table.getRows().add("", "No", "Name");
doc.getMailMerge().execute(table);
Assert.assertTrue(doc.getRange().getFields().getCount() == 0);
Assert.assertEquals("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
doc.getText().trim());
java.lang.Exceptionpublic int getSwitchType(java.lang.String switchName)
public Document iFormattableMergeField_FetchDocument()
public java.lang.String getMergeFormat()