Ewa.NamedItemCollection.getItemByName(name)
Applies to: apps for SharePoint | Excel Services | SharePoint Server 2013
In this article
Return Value
Remarks
Example
Applies To
Gets the named item with the matching name.
var value = Ewa.NamedItemCollection.getItemByName(name);
Parameters
name
Return Value
Named item
Remarks
The getItemByName method returns the specified named item using the friendly name of the named item as an index value. The method returns the named item with the lower index value if multiple named items have the same name. Returns null if the named item does not exist.
Example
The following code example shows how to add a button and a text input box to the page and then adds an event handler to the button onClick event that takes the name of the named item entered in the text box and gets the named item with that name. The event handler then displays the NamedItemType of the named item in an alert message. The code example assumes that you are working with Excel Web Access Web Parts on SharePoint Server 2013.
<script type="text/javascript">
var ewa = null;
// Add event handler for onload event.
if (window.attachEvent)
{
window.attachEvent("onload", ewaOnPageLoad);
}
else
{
window.addEventListener("DOMContentLoaded", ewaOnPageLoad, false);
}
// Add event handler for applicationReady event.
function ewaOnPageLoad()
{
Ewa.EwaControl.add_applicationReady(getEwa);
}
function getEwa()
{
// Get a reference to the Excel Services Web Part.
ewa = Ewa.EwaControl.getInstances().getItem(0);
}
// Get NamedItemType as string.
function getNamedItemTypeAsString(type)
{
var myType = null;
switch(type)
{
case Ewa.NamedItemType.NamedRange:
myType = "NamedRange";
break;
case Ewa.NamedItemType.Parameter:
myType = "Parameter";
break;
case Ewa.NamedItemType.Table:
myType = "Table";
break;
case Ewa.NamedItemType.PivotTable:
myType = "PivotTable";
break;
case Ewa.NamedItemType.Chart:
myType = "Chart";
break;
default:
myType = "undefined";
}
return myType;
}
// Use the button onClick event handler.
function getTypeButton()
{
// Get the name of the named item from the text box.
var niName = document.getElementById("EnterName").value;
// Get the NamedItems collection.
var items = ewa.getActiveWorkbook().getNamedItems();
// Get the specified named item in the collection by friendly name.
var item = items.getItemByName(niName);
if (item != null)
{
// Get the NamedItemType as a string.
var type = getNamedItemTypeAsString(item.getNamedItemType());
alert("Named item " + niName + " has a named item type of " + type + ".");
}
else
{
// No named item present with that friendly name.
alert("No named item by that name.");
}
}
</script>
<input type="text" id="EnterName" value="Enter name" />
<input type="button" id="GetNiType" value="Get Named Item Type" onclick="getTypeButton()" />
Applies To
Ewa.NamedItemCollection Object