public class FieldTitle extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves, and optionally sets, the document's title, as recorded in the Title property of the built-in document properties.
Examples:
Shows how to use the TITLE field.
Document doc = new Document();
// Set a value for the "Title" built-in document property.
doc.getBuiltInDocumentProperties().setTitle("My Title");
// We can use the TITLE field to display the value of this property in the document.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldTitle field = (FieldTitle) builder.insertField(FieldType.FIELD_TITLE, false);
field.update();
Assert.assertEquals(field.getFieldCode(), " TITLE ");
Assert.assertEquals(field.getResult(), "My Title");
// Setting a value for the field's Text property,
// and then updating the field will also overwrite the corresponding built-in property with the new value.
builder.writeln();
field = (FieldTitle) builder.insertField(FieldType.FIELD_TITLE, false);
field.setText("My New Title");
field.update();
Assert.assertEquals(" TITLE \"My New Title\"", field.getFieldCode());
Assert.assertEquals("My New Title", field.getResult());
Assert.assertEquals("My New Title", doc.getBuiltInDocumentProperties().getTitle());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.TITLE.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getText()
Gets the text of the title.
|
void |
setText(java.lang.String value)
Sets the text of the title.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getText()
Examples:
Shows how to use the TITLE field.
Document doc = new Document();
// Set a value for the "Title" built-in document property.
doc.getBuiltInDocumentProperties().setTitle("My Title");
// We can use the TITLE field to display the value of this property in the document.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldTitle field = (FieldTitle) builder.insertField(FieldType.FIELD_TITLE, false);
field.update();
Assert.assertEquals(field.getFieldCode(), " TITLE ");
Assert.assertEquals(field.getResult(), "My Title");
// Setting a value for the field's Text property,
// and then updating the field will also overwrite the corresponding built-in property with the new value.
builder.writeln();
field = (FieldTitle) builder.insertField(FieldType.FIELD_TITLE, false);
field.setText("My New Title");
field.update();
Assert.assertEquals(" TITLE \"My New Title\"", field.getFieldCode());
Assert.assertEquals("My New Title", field.getResult());
Assert.assertEquals("My New Title", doc.getBuiltInDocumentProperties().getTitle());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.TITLE.docx");
public void setText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use the TITLE field.
Document doc = new Document();
// Set a value for the "Title" built-in document property.
doc.getBuiltInDocumentProperties().setTitle("My Title");
// We can use the TITLE field to display the value of this property in the document.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldTitle field = (FieldTitle) builder.insertField(FieldType.FIELD_TITLE, false);
field.update();
Assert.assertEquals(field.getFieldCode(), " TITLE ");
Assert.assertEquals(field.getResult(), "My Title");
// Setting a value for the field's Text property,
// and then updating the field will also overwrite the corresponding built-in property with the new value.
builder.writeln();
field = (FieldTitle) builder.insertField(FieldType.FIELD_TITLE, false);
field.setText("My New Title");
field.update();
Assert.assertEquals(" TITLE \"My New Title\"", field.getFieldCode());
Assert.assertEquals("My New Title", field.getResult());
Assert.assertEquals("My New Title", doc.getBuiltInDocumentProperties().getTitle());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.TITLE.docx");
value - The text of the title.java.lang.Exception