Share via


Ewa.NamedItem.getNamedItemType()

Applies to: apps for SharePoint | Excel Services | SharePoint Server 2013

In this article
Return Value
Remarks
Example
Applies To

Gets the type of the named item.

var value = Ewa.NamedItem.getNamedItemType();

Return Value

Type: Ewa.NamedItemType

Remarks

The getNamedItemType method returns an Ewa.NamedItemType enumeration constant that specifies the type of the named item.

Example

The following code example shows how to loop through all the named items in the workbook and displays an alert message for each named item that shows the type of the named item. 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(onApplicationReady); 
} 

function onApplicationReady()
{            
    // 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;    
}

        
function getTypeButton()
{    
    // Get the specified workbook.
    var wkBook = ewa.getActiveWorkbook();    
    // Get the NamedItems collection.
    var items = wkBook.getNamedItems();
    var type = null;
    
    if (items)
    {
        for (i=0;i<items.getCount();i++)
        {
            type = items.getItem(i).getNamedItemType();
            alert("Named item #" + (i + 1) + " is of type " + getNamedItemTypeAsString(type) + ".");
        }
    }
    else
    {
        alert("There are no named items.");
    }
}


</script>
<input type="button" id="GetType" value="Get Named Item Type" onclick="getTypeButton()" /> 

Applies To

Ewa.NamedItem Object

See also

Concepts

Ewa.NamedItem Methods

Ewa namespace