public class FieldAuthor extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves, and optionally sets, the document author's name, as recorded in the Author property of the built-in document properties.
Examples:
Shows how to use an AUTHOR field to display a document creator's name.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// AUTHOR fields source their results from the built-in document property called "Author".
// If we create and save a document in Microsoft Word,
// it will have our username in that property.
// However, if we create a document programmatically using Aspose.Words,
// the "Author" property, by default, will be an empty string.
Assert.assertEquals("", doc.getBuiltInDocumentProperties().getAuthor());
// Set a backup author name for AUTHOR fields to use
// if the "Author" property contains an empty string.
doc.getFieldOptions().setDefaultDocumentAuthor("Joe Bloggs");
builder.write("This document was created by ");
FieldAuthor field = (FieldAuthor) builder.insertField(FieldType.FIELD_AUTHOR, true);
field.update();
Assert.assertEquals(" AUTHOR ", field.getFieldCode());
Assert.assertEquals("Joe Bloggs", field.getResult());
// Updating an AUTHOR field that contains a value
// will apply that value to the "Author" built-in property.
Assert.assertEquals("Joe Bloggs", doc.getBuiltInDocumentProperties().getAuthor());
// Changing this property, then updating the AUTHOR field will apply this value to the field.
doc.getBuiltInDocumentProperties().setAuthor("John Doe");
field.update();
Assert.assertEquals(" AUTHOR ", field.getFieldCode());
Assert.assertEquals("John Doe", field.getResult());
// If we update an AUTHOR field after changing its "Name" property,
// then the field will display the new name and apply the new name to the built-in property.
field.setAuthorName("Jane Doe");
field.update();
Assert.assertEquals(field.getFieldCode(), " AUTHOR \"Jane Doe\"");
Assert.assertEquals(field.getResult(), "Jane Doe");
// AUTHOR fields do not affect the DefaultDocumentAuthor property.
Assert.assertEquals("Jane Doe", doc.getBuiltInDocumentProperties().getAuthor());
Assert.assertEquals("Joe Bloggs", doc.getFieldOptions().getDefaultDocumentAuthor());
doc.save(getArtifactsDir() + "Field.AUTHOR.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getAuthorName()
Gets the document author's name.
|
void |
setAuthorName(java.lang.String value)
Sets the document author's name.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getAuthorName()
Examples:
Shows how to use an AUTHOR field to display a document creator's name.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// AUTHOR fields source their results from the built-in document property called "Author".
// If we create and save a document in Microsoft Word,
// it will have our username in that property.
// However, if we create a document programmatically using Aspose.Words,
// the "Author" property, by default, will be an empty string.
Assert.assertEquals("", doc.getBuiltInDocumentProperties().getAuthor());
// Set a backup author name for AUTHOR fields to use
// if the "Author" property contains an empty string.
doc.getFieldOptions().setDefaultDocumentAuthor("Joe Bloggs");
builder.write("This document was created by ");
FieldAuthor field = (FieldAuthor) builder.insertField(FieldType.FIELD_AUTHOR, true);
field.update();
Assert.assertEquals(" AUTHOR ", field.getFieldCode());
Assert.assertEquals("Joe Bloggs", field.getResult());
// Updating an AUTHOR field that contains a value
// will apply that value to the "Author" built-in property.
Assert.assertEquals("Joe Bloggs", doc.getBuiltInDocumentProperties().getAuthor());
// Changing this property, then updating the AUTHOR field will apply this value to the field.
doc.getBuiltInDocumentProperties().setAuthor("John Doe");
field.update();
Assert.assertEquals(" AUTHOR ", field.getFieldCode());
Assert.assertEquals("John Doe", field.getResult());
// If we update an AUTHOR field after changing its "Name" property,
// then the field will display the new name and apply the new name to the built-in property.
field.setAuthorName("Jane Doe");
field.update();
Assert.assertEquals(field.getFieldCode(), " AUTHOR \"Jane Doe\"");
Assert.assertEquals(field.getResult(), "Jane Doe");
// AUTHOR fields do not affect the DefaultDocumentAuthor property.
Assert.assertEquals("Jane Doe", doc.getBuiltInDocumentProperties().getAuthor());
Assert.assertEquals("Joe Bloggs", doc.getFieldOptions().getDefaultDocumentAuthor());
doc.save(getArtifactsDir() + "Field.AUTHOR.docx");
public void setAuthorName(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use an AUTHOR field to display a document creator's name.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// AUTHOR fields source their results from the built-in document property called "Author".
// If we create and save a document in Microsoft Word,
// it will have our username in that property.
// However, if we create a document programmatically using Aspose.Words,
// the "Author" property, by default, will be an empty string.
Assert.assertEquals("", doc.getBuiltInDocumentProperties().getAuthor());
// Set a backup author name for AUTHOR fields to use
// if the "Author" property contains an empty string.
doc.getFieldOptions().setDefaultDocumentAuthor("Joe Bloggs");
builder.write("This document was created by ");
FieldAuthor field = (FieldAuthor) builder.insertField(FieldType.FIELD_AUTHOR, true);
field.update();
Assert.assertEquals(" AUTHOR ", field.getFieldCode());
Assert.assertEquals("Joe Bloggs", field.getResult());
// Updating an AUTHOR field that contains a value
// will apply that value to the "Author" built-in property.
Assert.assertEquals("Joe Bloggs", doc.getBuiltInDocumentProperties().getAuthor());
// Changing this property, then updating the AUTHOR field will apply this value to the field.
doc.getBuiltInDocumentProperties().setAuthor("John Doe");
field.update();
Assert.assertEquals(" AUTHOR ", field.getFieldCode());
Assert.assertEquals("John Doe", field.getResult());
// If we update an AUTHOR field after changing its "Name" property,
// then the field will display the new name and apply the new name to the built-in property.
field.setAuthorName("Jane Doe");
field.update();
Assert.assertEquals(field.getFieldCode(), " AUTHOR \"Jane Doe\"");
Assert.assertEquals(field.getResult(), "Jane Doe");
// AUTHOR fields do not affect the DefaultDocumentAuthor property.
Assert.assertEquals("Jane Doe", doc.getBuiltInDocumentProperties().getAuthor());
Assert.assertEquals("Joe Bloggs", doc.getFieldOptions().getDefaultDocumentAuthor());
doc.save(getArtifactsDir() + "Field.AUTHOR.docx");
value - The document author's name.java.lang.Exception