public class FieldQuote extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves the specified text.
Examples:
Shows to use the QUOTE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a QUOTE field, which will display the value of its Text property.
FieldQuote field = (FieldQuote) builder.insertField(FieldType.FIELD_QUOTE, true);
field.setText("\"Quoted text\"");
Assert.assertEquals(" QUOTE \"\\\"Quoted text\\\"\"", field.getFieldCode());
// Insert a QUOTE field and nest a DATE field inside it.
// DATE fields update their value to the current date every time we open the document using Microsoft Word.
// Nesting the DATE field inside the QUOTE field like this will freeze its value
// to the date when we created the document.
builder.write("\nDocument creation date: ");
field = (FieldQuote) builder.insertField(FieldType.FIELD_QUOTE, true);
builder.moveTo(field.getSeparator());
builder.insertField(FieldType.FIELD_DATE, true);
Assert.assertEquals(" QUOTE DATE " + LocalDate.now().format(DateTimeFormatter.ofPattern("M/d/YYYY")) + "", field.getFieldCode());
// Update all the fields to display their correct results.
doc.updateFields();
Assert.assertEquals("\"Quoted text\"", doc.getRange().getFields().get(0).getResult());
doc.save(getArtifactsDir() + "Field.QUOTE.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getText()
Gets the text to retrieve.
|
void |
setText(java.lang.String value)
Sets the text to retrieve.
|
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 to use the QUOTE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a QUOTE field, which will display the value of its Text property.
FieldQuote field = (FieldQuote) builder.insertField(FieldType.FIELD_QUOTE, true);
field.setText("\"Quoted text\"");
Assert.assertEquals(" QUOTE \"\\\"Quoted text\\\"\"", field.getFieldCode());
// Insert a QUOTE field and nest a DATE field inside it.
// DATE fields update their value to the current date every time we open the document using Microsoft Word.
// Nesting the DATE field inside the QUOTE field like this will freeze its value
// to the date when we created the document.
builder.write("\nDocument creation date: ");
field = (FieldQuote) builder.insertField(FieldType.FIELD_QUOTE, true);
builder.moveTo(field.getSeparator());
builder.insertField(FieldType.FIELD_DATE, true);
Assert.assertEquals(" QUOTE DATE " + LocalDate.now().format(DateTimeFormatter.ofPattern("M/d/YYYY")) + "", field.getFieldCode());
// Update all the fields to display their correct results.
doc.updateFields();
Assert.assertEquals("\"Quoted text\"", doc.getRange().getFields().get(0).getResult());
doc.save(getArtifactsDir() + "Field.QUOTE.docx");
public void setText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows to use the QUOTE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a QUOTE field, which will display the value of its Text property.
FieldQuote field = (FieldQuote) builder.insertField(FieldType.FIELD_QUOTE, true);
field.setText("\"Quoted text\"");
Assert.assertEquals(" QUOTE \"\\\"Quoted text\\\"\"", field.getFieldCode());
// Insert a QUOTE field and nest a DATE field inside it.
// DATE fields update their value to the current date every time we open the document using Microsoft Word.
// Nesting the DATE field inside the QUOTE field like this will freeze its value
// to the date when we created the document.
builder.write("\nDocument creation date: ");
field = (FieldQuote) builder.insertField(FieldType.FIELD_QUOTE, true);
builder.moveTo(field.getSeparator());
builder.insertField(FieldType.FIELD_DATE, true);
Assert.assertEquals(" QUOTE DATE " + LocalDate.now().format(DateTimeFormatter.ofPattern("M/d/YYYY")) + "", field.getFieldCode());
// Update all the fields to display their correct results.
doc.updateFields();
Assert.assertEquals("\"Quoted text\"", doc.getRange().getFields().get(0).getResult());
doc.save(getArtifactsDir() + "Field.QUOTE.docx");
value - The text to retrieve.java.lang.Exception