Compartilhar via


Ewa.NamedItem.getNamedItemType()

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example
Applies To

Gets the type of the named item.

var value = Ewa.NamedItem.getNamedItemType();

Return Value

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.

<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);                                   
}              

// 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