T - Type of a collection item.
Examples:
Shows how to work with a document's collection of web extensions.
Document doc = new Document(getMyDir() + "Web extension.docx");
Assert.assertEquals(1, doc.getWebExtensionTaskPanes().getCount());
// Print all properties of the document's web extension.
WebExtensionPropertyCollection webExtensionPropertyCollection = doc.getWebExtensionTaskPanes().get(0).getWebExtension().getProperties();
Iterator<WebExtensionProperty> enumerator = webExtensionPropertyCollection.iterator();
while (enumerator.hasNext()) {
WebExtensionProperty webExtensionProperty = enumerator.next();
System.out.println("Binding name: {webExtensionProperty.Name}; Binding value: {webExtensionProperty.Value}");
}
// Remove the web extension.
doc.getWebExtensionTaskPanes().remove(0);
Assert.assertEquals(0, doc.getWebExtensionTaskPanes().getCount());
public abstract class BaseWebExtensionCollection
extends java.lang.Object
implements java.lang.Iterable
TaskPaneCollection, WebExtensionBindingCollection, WebExtensionPropertyCollection and WebExtensionReferenceCollection collections.
To learn more, visit the Work with Office Add-ins documentation article.
| Constructor and Description |
|---|
BaseWebExtensionCollection() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.Object item) |
void |
clear()
Removes all elements from the collection.
|
java.lang.Object |
get(int index)
Gets an item at the specified index.
|
int |
getCount()
Gets the number of elements contained in the collection.
|
java.util.Iterator |
iterator()
Returns an enumerator that can iterate through a collection.
|
void |
remove(int index)
Removes the item at the specified index from the collection.
|
void |
set(int index,
java.lang.Object value)
Sets an item at the specified index.
|
public int getCount()
Examples:
Shows how to work with a document's collection of web extensions.
Document doc = new Document(getMyDir() + "Web extension.docx");
Assert.assertEquals(1, doc.getWebExtensionTaskPanes().getCount());
// Print all properties of the document's web extension.
WebExtensionPropertyCollection webExtensionPropertyCollection = doc.getWebExtensionTaskPanes().get(0).getWebExtension().getProperties();
Iterator<WebExtensionProperty> enumerator = webExtensionPropertyCollection.iterator();
while (enumerator.hasNext()) {
WebExtensionProperty webExtensionProperty = enumerator.next();
System.out.println("Binding name: {webExtensionProperty.Name}; Binding value: {webExtensionProperty.Value}");
}
// Remove the web extension.
doc.getWebExtensionTaskPanes().remove(0);
Assert.assertEquals(0, doc.getWebExtensionTaskPanes().getCount());
public java.lang.Object get(int index)
Examples:
Shows how to work with a document's collection of web extensions.
Document doc = new Document(getMyDir() + "Web extension.docx");
Assert.assertEquals(1, doc.getWebExtensionTaskPanes().getCount());
// Print all properties of the document's web extension.
WebExtensionPropertyCollection webExtensionPropertyCollection = doc.getWebExtensionTaskPanes().get(0).getWebExtension().getProperties();
Iterator<WebExtensionProperty> enumerator = webExtensionPropertyCollection.iterator();
while (enumerator.hasNext()) {
WebExtensionProperty webExtensionProperty = enumerator.next();
System.out.println("Binding name: {webExtensionProperty.Name}; Binding value: {webExtensionProperty.Value}");
}
// Remove the web extension.
doc.getWebExtensionTaskPanes().remove(0);
Assert.assertEquals(0, doc.getWebExtensionTaskPanes().getCount());
index - Zero-based index of the item.public void set(int index,
java.lang.Object value)
Examples:
Shows how to work with a document's collection of web extensions.
Document doc = new Document(getMyDir() + "Web extension.docx");
Assert.assertEquals(1, doc.getWebExtensionTaskPanes().getCount());
// Print all properties of the document's web extension.
WebExtensionPropertyCollection webExtensionPropertyCollection = doc.getWebExtensionTaskPanes().get(0).getWebExtension().getProperties();
Iterator<WebExtensionProperty> enumerator = webExtensionPropertyCollection.iterator();
while (enumerator.hasNext()) {
WebExtensionProperty webExtensionProperty = enumerator.next();
System.out.println("Binding name: {webExtensionProperty.Name}; Binding value: {webExtensionProperty.Value}");
}
// Remove the web extension.
doc.getWebExtensionTaskPanes().remove(0);
Assert.assertEquals(0, doc.getWebExtensionTaskPanes().getCount());
index - Zero-based index of the item.value - An item at the specified index.public void add(java.lang.Object item)
public void clear()
Examples:
Shows how to add a web extension to a document.
Document doc = new Document();
// Create task pane with "MyScript" add-in, which will be used by the document,
// then set its default location.
TaskPane myScriptTaskPane = new TaskPane();
doc.getWebExtensionTaskPanes().add(myScriptTaskPane);
myScriptTaskPane.setDockState(TaskPaneDockState.RIGHT);
myScriptTaskPane.isVisible(true);
myScriptTaskPane.setWidth(300.0);
myScriptTaskPane.isLocked(true);
// If there are multiple task panes in the same docking location, we can set this index to arrange them.
myScriptTaskPane.setRow(1);
// Create an add-in called "MyScript Math Sample", which the task pane will display within.
WebExtension webExtension = myScriptTaskPane.getWebExtension();
// Set application store reference parameters for our add-in, such as the ID.
webExtension.getReference().setId("WA104380646");
webExtension.getReference().setVersion("1.0.0.0");
webExtension.getReference().setStoreType(WebExtensionStoreType.OMEX);
webExtension.getReference().setStore("English (United States)");
webExtension.getProperties().add(new WebExtensionProperty("MyScript", "MyScript Math Sample"));
webExtension.getBindings().add(new WebExtensionBinding("MyScript", WebExtensionBindingType.TEXT, "104380646"));
// Allow the user to interact with the add-in.
webExtension.isFrozen(false);
// We can access the web extension in Microsoft Word via Developer -> Add-ins.
doc.save(getArtifactsDir() + "Document.WebExtension.docx");
// Remove all web extension task panes at once like this.
doc.getWebExtensionTaskPanes().clear();
Assert.assertEquals(0, doc.getWebExtensionTaskPanes().getCount());
doc = new Document(getArtifactsDir() + "Document.WebExtension.docx");
myScriptTaskPane = doc.getWebExtensionTaskPanes().get(0);
Assert.assertEquals(TaskPaneDockState.RIGHT, myScriptTaskPane.getDockState());
Assert.assertTrue(myScriptTaskPane.isVisible());
Assert.assertEquals(300.0d, myScriptTaskPane.getWidth());
Assert.assertTrue(myScriptTaskPane.isLocked());
Assert.assertEquals(1, myScriptTaskPane.getRow());
webExtension = myScriptTaskPane.getWebExtension();
Assert.assertEquals("", webExtension.getId());
Assert.assertEquals("WA104380646", webExtension.getReference().getId());
Assert.assertEquals("1.0.0.0", webExtension.getReference().getVersion());
Assert.assertEquals(WebExtensionStoreType.OMEX, webExtension.getReference().getStoreType());
Assert.assertEquals("English (United States)", webExtension.getReference().getStore());
Assert.assertEquals(0, webExtension.getAlternateReferences().getCount());
Assert.assertEquals("MyScript", webExtension.getProperties().get(0).getName());
Assert.assertEquals("MyScript Math Sample", webExtension.getProperties().get(0).getValue());
Assert.assertEquals("MyScript", webExtension.getBindings().get(0).getId());
Assert.assertEquals(WebExtensionBindingType.TEXT, webExtension.getBindings().get(0).getBindingType());
Assert.assertEquals("104380646", webExtension.getBindings().get(0).getAppRef());
Assert.assertFalse(webExtension.isFrozen());
public void remove(int index)
Examples:
Shows how to work with a document's collection of web extensions.
Document doc = new Document(getMyDir() + "Web extension.docx");
Assert.assertEquals(1, doc.getWebExtensionTaskPanes().getCount());
// Print all properties of the document's web extension.
WebExtensionPropertyCollection webExtensionPropertyCollection = doc.getWebExtensionTaskPanes().get(0).getWebExtension().getProperties();
Iterator<WebExtensionProperty> enumerator = webExtensionPropertyCollection.iterator();
while (enumerator.hasNext()) {
WebExtensionProperty webExtensionProperty = enumerator.next();
System.out.println("Binding name: {webExtensionProperty.Name}; Binding value: {webExtensionProperty.Value}");
}
// Remove the web extension.
doc.getWebExtensionTaskPanes().remove(0);
Assert.assertEquals(0, doc.getWebExtensionTaskPanes().getCount());
index - The zero-based index of the collection item.public java.util.Iterator iterator()
Examples:
Shows how to work with a document's collection of web extensions.
Document doc = new Document(getMyDir() + "Web extension.docx");
Assert.assertEquals(1, doc.getWebExtensionTaskPanes().getCount());
// Print all properties of the document's web extension.
WebExtensionPropertyCollection webExtensionPropertyCollection = doc.getWebExtensionTaskPanes().get(0).getWebExtension().getProperties();
Iterator<WebExtensionProperty> enumerator = webExtensionPropertyCollection.iterator();
while (enumerator.hasNext()) {
WebExtensionProperty webExtensionProperty = enumerator.next();
System.out.println("Binding name: {webExtensionProperty.Name}; Binding value: {webExtensionProperty.Value}");
}
// Remove the web extension.
doc.getWebExtensionTaskPanes().remove(0);
Assert.assertEquals(0, doc.getWebExtensionTaskPanes().getCount());
iterator in interface java.lang.Iterable