public class FieldMacroButton extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Allows a macro or command to be run.
In Aspose.Words this field can also act as a merge field.
Examples:
Shows how to use MACROBUTTON fields to allow us to run a document's macros by clicking.
Document doc = new Document(getMyDir() + "Macro.docm");
DocumentBuilder builder = new DocumentBuilder(doc);
Assert.assertTrue(doc.hasMacros());
// Insert a MACROBUTTON field, and reference one of the document's macros by name in the MacroName property.
FieldMacroButton field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("MyMacro");
field.setDisplayText("Double click to run macro: " + field.getMacroName());
Assert.assertEquals(" MACROBUTTON MyMacro Double click to run macro: MyMacro", field.getFieldCode());
// Use the property to reference "ViewZoom200", a macro that ships with Microsoft Word.
// We can find all other macros via View -> Macros (dropdown) -> View Macros.
// In that menu, select "Word Commands" from the "Macros in:" drop down.
// If our document contains a custom macro with the same name as a stock macro,
// our macro will be the one that the MACROBUTTON field runs.
builder.insertParagraph();
field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("ViewZoom200");
field.setDisplayText("Run " + field.getMacroName());
Assert.assertEquals(field.getFieldCode(), " MACROBUTTON ViewZoom200 Run ViewZoom200");
// Save the document as a macro-enabled document type.
doc.save(getArtifactsDir() + "Field.MACROBUTTON.docm");
| Modifier and Type | Method and Description |
|---|---|
boolean |
canWorkAsMergeField() |
java.lang.String |
getDisplayText()
Gets the text to appear as the "button" that is selected to run the macro or command.
|
java.lang.String |
getMacroName()
Gets the name of the macro or command to run.
|
java.lang.String |
getMergeFieldName() |
boolean |
isMergeValueRequired() |
void |
setDisplayText(java.lang.String value)
Sets the text to appear as the "button" that is selected to run the macro or command.
|
void |
setMacroName(java.lang.String value)
Sets the name of the macro or command to run.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getMergeFieldName()
public boolean canWorkAsMergeField()
public boolean isMergeValueRequired()
public java.lang.String getMacroName()
Examples:
Shows how to use MACROBUTTON fields to allow us to run a document's macros by clicking.
Document doc = new Document(getMyDir() + "Macro.docm");
DocumentBuilder builder = new DocumentBuilder(doc);
Assert.assertTrue(doc.hasMacros());
// Insert a MACROBUTTON field, and reference one of the document's macros by name in the MacroName property.
FieldMacroButton field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("MyMacro");
field.setDisplayText("Double click to run macro: " + field.getMacroName());
Assert.assertEquals(" MACROBUTTON MyMacro Double click to run macro: MyMacro", field.getFieldCode());
// Use the property to reference "ViewZoom200", a macro that ships with Microsoft Word.
// We can find all other macros via View -> Macros (dropdown) -> View Macros.
// In that menu, select "Word Commands" from the "Macros in:" drop down.
// If our document contains a custom macro with the same name as a stock macro,
// our macro will be the one that the MACROBUTTON field runs.
builder.insertParagraph();
field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("ViewZoom200");
field.setDisplayText("Run " + field.getMacroName());
Assert.assertEquals(field.getFieldCode(), " MACROBUTTON ViewZoom200 Run ViewZoom200");
// Save the document as a macro-enabled document type.
doc.save(getArtifactsDir() + "Field.MACROBUTTON.docm");
public void setMacroName(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use MACROBUTTON fields to allow us to run a document's macros by clicking.
Document doc = new Document(getMyDir() + "Macro.docm");
DocumentBuilder builder = new DocumentBuilder(doc);
Assert.assertTrue(doc.hasMacros());
// Insert a MACROBUTTON field, and reference one of the document's macros by name in the MacroName property.
FieldMacroButton field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("MyMacro");
field.setDisplayText("Double click to run macro: " + field.getMacroName());
Assert.assertEquals(" MACROBUTTON MyMacro Double click to run macro: MyMacro", field.getFieldCode());
// Use the property to reference "ViewZoom200", a macro that ships with Microsoft Word.
// We can find all other macros via View -> Macros (dropdown) -> View Macros.
// In that menu, select "Word Commands" from the "Macros in:" drop down.
// If our document contains a custom macro with the same name as a stock macro,
// our macro will be the one that the MACROBUTTON field runs.
builder.insertParagraph();
field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("ViewZoom200");
field.setDisplayText("Run " + field.getMacroName());
Assert.assertEquals(field.getFieldCode(), " MACROBUTTON ViewZoom200 Run ViewZoom200");
// Save the document as a macro-enabled document type.
doc.save(getArtifactsDir() + "Field.MACROBUTTON.docm");
value - The name of the macro or command to run.java.lang.Exceptionpublic java.lang.String getDisplayText()
Examples:
Shows how to use MACROBUTTON fields to allow us to run a document's macros by clicking.
Document doc = new Document(getMyDir() + "Macro.docm");
DocumentBuilder builder = new DocumentBuilder(doc);
Assert.assertTrue(doc.hasMacros());
// Insert a MACROBUTTON field, and reference one of the document's macros by name in the MacroName property.
FieldMacroButton field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("MyMacro");
field.setDisplayText("Double click to run macro: " + field.getMacroName());
Assert.assertEquals(" MACROBUTTON MyMacro Double click to run macro: MyMacro", field.getFieldCode());
// Use the property to reference "ViewZoom200", a macro that ships with Microsoft Word.
// We can find all other macros via View -> Macros (dropdown) -> View Macros.
// In that menu, select "Word Commands" from the "Macros in:" drop down.
// If our document contains a custom macro with the same name as a stock macro,
// our macro will be the one that the MACROBUTTON field runs.
builder.insertParagraph();
field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("ViewZoom200");
field.setDisplayText("Run " + field.getMacroName());
Assert.assertEquals(field.getFieldCode(), " MACROBUTTON ViewZoom200 Run ViewZoom200");
// Save the document as a macro-enabled document type.
doc.save(getArtifactsDir() + "Field.MACROBUTTON.docm");
public void setDisplayText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use MACROBUTTON fields to allow us to run a document's macros by clicking.
Document doc = new Document(getMyDir() + "Macro.docm");
DocumentBuilder builder = new DocumentBuilder(doc);
Assert.assertTrue(doc.hasMacros());
// Insert a MACROBUTTON field, and reference one of the document's macros by name in the MacroName property.
FieldMacroButton field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("MyMacro");
field.setDisplayText("Double click to run macro: " + field.getMacroName());
Assert.assertEquals(" MACROBUTTON MyMacro Double click to run macro: MyMacro", field.getFieldCode());
// Use the property to reference "ViewZoom200", a macro that ships with Microsoft Word.
// We can find all other macros via View -> Macros (dropdown) -> View Macros.
// In that menu, select "Word Commands" from the "Macros in:" drop down.
// If our document contains a custom macro with the same name as a stock macro,
// our macro will be the one that the MACROBUTTON field runs.
builder.insertParagraph();
field = (FieldMacroButton) builder.insertField(FieldType.FIELD_MACRO_BUTTON, true);
field.setMacroName("ViewZoom200");
field.setDisplayText("Run " + field.getMacroName());
Assert.assertEquals(field.getFieldCode(), " MACROBUTTON ViewZoom200 Run ViewZoom200");
// Save the document as a macro-enabled document type.
doc.save(getArtifactsDir() + "Field.MACROBUTTON.docm");
value - The text to appear as the "button" that is selected to run the macro or command.java.lang.Exception