Ewa.NamedItemCollection.getItem(index)
Applies to: apps for SharePoint | SharePoint Server 2010
In this article
Return Value
Remarks
Example
Gets the nth named item.
var value = Ewa.NamedItemCollection.getItem(index);
Parameters
index
An integer value that specifies the ordinal position of the named item in the named items collection.
Return Value
Named item
Remarks
The getItem method returns the specified named item using the index value of the named item. The index is zero-based and returns null if the nth named item does not exist.
Example
The following code example shows how to add a button to the page and then adds an event handler for the button onClick event that loops through all the named items in the workbook and displays an alert message for each named item that contains the name of the named item.
<script type="text/javascript">
var ewa = null;
// Add event handler for onload event.
if (window.attachEvent)
{
window.attachEvent("onload", ewaOmPageLoad);
}
else
{
window.addEventListener("DOMContentLoaded", ewaOmPageLoad, false);
}
// Add event handler for applicationReady event.
function ewaOmPageLoad()
{
Ewa.EwaControl.add_applicationReady(getEwa);
}
function getEwa()
{
// Get a reference to the Excel Services Web Part.
ewa = Ewa.EwaControl.getInstances().getItem(0);
}
function getNamedItemsNamesButton()
{
// Get the specified workbook.
var wkBook = ewa.getActiveWorkbook();
// Get the NamedItems collection.
var items = wkBook.getNamedItems();
for (i=0;i<items.getCount();i++)
{
alert(items.getItem(i).getName());
}
}
</script>
<input type="button" id="GetNamedItemsNames" value="Get Named Items Names" onclick="getNamedItemsNamesButton()" />