public class FieldShape extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves the specified text.
Examples:
Shows how to create right-to-left language-compatible lists with BIDIOUTLINE fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// The BIDIOUTLINE field numbers paragraphs like the AUTONUM/LISTNUM fields,
// but is only visible when a right-to-left editing language is enabled, such as Hebrew or Arabic.
// The following field will display ".1", the RTL equivalent of list number "1.".
FieldBidiOutline field = (FieldBidiOutline) builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
Assert.assertEquals(" BIDIOUTLINE ", field.getFieldCode());
// Add two more BIDIOUTLINE fields, which will display ".2" and ".3".
builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
// Set the horizontal text alignment for every paragraph in the document to RTL.
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
para.getParagraphFormat().setBidi(true);
}
// If we enable a right-to-left editing language in Microsoft Word, our fields will display numbers.
// Otherwise, they will display "###".
doc.save(getArtifactsDir() + "Field.BIDIOUTLINE.docx");
Shows how some older Microsoft Word fields such as SHAPE and EMBED are handled during loading.
// Open a document that was created in Microsoft Word 2003.
Document doc = new Document(getMyDir() + "Legacy fields.doc");
// If we open the Word document and press Alt+F9, we will see a SHAPE and an EMBED field.
// A SHAPE field is the anchor/canvas for an AutoShape object with the "In line with text" wrapping style enabled.
// An EMBED field has the same function, but for an embedded object,
// such as a spreadsheet from an external Excel document.
// However, these fields will not appear in the document's Fields collection.
Assert.assertEquals(0, doc.getRange().getFields().getCount());
// These fields are supported only by old versions of Microsoft Word.
// The document loading process will convert these fields into Shape objects,
// which we can access in the document's node collection.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
Assert.assertEquals(shapes.getCount(), 3);
// The first Shape node corresponds to the SHAPE field in the input document,
// which is the inline canvas for the AutoShape.
Shape shape = (Shape) shapes.get(0);
Assert.assertEquals(ShapeType.IMAGE, shape.getShapeType());
// The second Shape node is the AutoShape itself.
shape = (Shape) shapes.get(1);
Assert.assertEquals(ShapeType.CAN, shape.getShapeType());
// The third Shape is what was the EMBED field that contained the external spreadsheet.
shape = (Shape) shapes.get(2);
Assert.assertEquals(ShapeType.OLE_OBJECT, shape.getShapeType());
| 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 how to create right-to-left language-compatible lists with BIDIOUTLINE fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// The BIDIOUTLINE field numbers paragraphs like the AUTONUM/LISTNUM fields,
// but is only visible when a right-to-left editing language is enabled, such as Hebrew or Arabic.
// The following field will display ".1", the RTL equivalent of list number "1.".
FieldBidiOutline field = (FieldBidiOutline) builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
Assert.assertEquals(" BIDIOUTLINE ", field.getFieldCode());
// Add two more BIDIOUTLINE fields, which will display ".2" and ".3".
builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
// Set the horizontal text alignment for every paragraph in the document to RTL.
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
para.getParagraphFormat().setBidi(true);
}
// If we enable a right-to-left editing language in Microsoft Word, our fields will display numbers.
// Otherwise, they will display "###".
doc.save(getArtifactsDir() + "Field.BIDIOUTLINE.docx");
Shows how some older Microsoft Word fields such as SHAPE and EMBED are handled during loading.
// Open a document that was created in Microsoft Word 2003.
Document doc = new Document(getMyDir() + "Legacy fields.doc");
// If we open the Word document and press Alt+F9, we will see a SHAPE and an EMBED field.
// A SHAPE field is the anchor/canvas for an AutoShape object with the "In line with text" wrapping style enabled.
// An EMBED field has the same function, but for an embedded object,
// such as a spreadsheet from an external Excel document.
// However, these fields will not appear in the document's Fields collection.
Assert.assertEquals(0, doc.getRange().getFields().getCount());
// These fields are supported only by old versions of Microsoft Word.
// The document loading process will convert these fields into Shape objects,
// which we can access in the document's node collection.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
Assert.assertEquals(shapes.getCount(), 3);
// The first Shape node corresponds to the SHAPE field in the input document,
// which is the inline canvas for the AutoShape.
Shape shape = (Shape) shapes.get(0);
Assert.assertEquals(ShapeType.IMAGE, shape.getShapeType());
// The second Shape node is the AutoShape itself.
shape = (Shape) shapes.get(1);
Assert.assertEquals(ShapeType.CAN, shape.getShapeType());
// The third Shape is what was the EMBED field that contained the external spreadsheet.
shape = (Shape) shapes.get(2);
Assert.assertEquals(ShapeType.OLE_OBJECT, shape.getShapeType());
public void setText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to create right-to-left language-compatible lists with BIDIOUTLINE fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// The BIDIOUTLINE field numbers paragraphs like the AUTONUM/LISTNUM fields,
// but is only visible when a right-to-left editing language is enabled, such as Hebrew or Arabic.
// The following field will display ".1", the RTL equivalent of list number "1.".
FieldBidiOutline field = (FieldBidiOutline) builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
Assert.assertEquals(" BIDIOUTLINE ", field.getFieldCode());
// Add two more BIDIOUTLINE fields, which will display ".2" and ".3".
builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
builder.writeln("שלום");
// Set the horizontal text alignment for every paragraph in the document to RTL.
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
para.getParagraphFormat().setBidi(true);
}
// If we enable a right-to-left editing language in Microsoft Word, our fields will display numbers.
// Otherwise, they will display "###".
doc.save(getArtifactsDir() + "Field.BIDIOUTLINE.docx");
Shows how some older Microsoft Word fields such as SHAPE and EMBED are handled during loading.
// Open a document that was created in Microsoft Word 2003.
Document doc = new Document(getMyDir() + "Legacy fields.doc");
// If we open the Word document and press Alt+F9, we will see a SHAPE and an EMBED field.
// A SHAPE field is the anchor/canvas for an AutoShape object with the "In line with text" wrapping style enabled.
// An EMBED field has the same function, but for an embedded object,
// such as a spreadsheet from an external Excel document.
// However, these fields will not appear in the document's Fields collection.
Assert.assertEquals(0, doc.getRange().getFields().getCount());
// These fields are supported only by old versions of Microsoft Word.
// The document loading process will convert these fields into Shape objects,
// which we can access in the document's node collection.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
Assert.assertEquals(shapes.getCount(), 3);
// The first Shape node corresponds to the SHAPE field in the input document,
// which is the inline canvas for the AutoShape.
Shape shape = (Shape) shapes.get(0);
Assert.assertEquals(ShapeType.IMAGE, shape.getShapeType());
// The second Shape node is the AutoShape itself.
shape = (Shape) shapes.get(1);
Assert.assertEquals(ShapeType.CAN, shape.getShapeType());
// The third Shape is what was the EMBED field that contained the external spreadsheet.
shape = (Shape) shapes.get(2);
Assert.assertEquals(ShapeType.OLE_OBJECT, shape.getShapeType());
value - The text to retrieve.java.lang.Exception