Export (0) Print
Expand All

Ewa.NamedItemCollection Object

Last modified: June 13, 2011

Applies to: apps for SharePoint | SharePoint Server 2010

Represents the collection of the named items in a workbook.

Ewa.NamedItemCollection

The NamedItemCollection represents all the named items in a workbook. To get a reference to the named item collection, use the Workbook.getNamedItems method.

Note Note

In named item view mode, the Workbook.getNamedItems method returns only published items. In sheet view mode, Workbook.getNamedItems returns all the publishable items in the workbook.

Additionally, Workbook.getNamedItems returns only those items present at the time the workbook loads. For example, if a table is added or deleted dynamically, Workbook.getNamedItems will not reflect those changes.

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 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()" />
Show:
© 2014 Microsoft