Ewa.Workbook.getActiveNamedItem()

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example
Applies To

Gets the active named item object (only in named item view).

var value = Ewa.Workbook.getActiveNamedItem();

Return Value

NamedItem

Remarks

The Ewa.Workbook.getActiveNamedItem method returns the active named item. Ewa.Workbook.getActiveNamedItem returns null if not in named item view.

Example

The following code example shows how to add a button the page and then adds an event handler to the button onClick event that gets the named item type and name of the named item and displays that information in the browser status bar.

<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 getActiveNamedItemButton()
{    
    // Get a reference to the workbook.
    var wkBook = ewa.getActiveWorkbook();    
        
    // Only run if in Named Item view.
    if (wkBook.getIsNamedItemView())
    {             
        // Activate the active named item.
        // Pass in named item as userContext.
        var item = wkBook.getActiveNamedItem();
        
        // Get NamedItemType as string.
        var type = getNamedItemTypeAsString(item.getNamedItemType());
    
        // Display name and type of active named item.
        window.status = "Named item " + item.getName() + " with NamedItemType of " + type + " is active.";
    }    
    else
    {
        alert("Not in Named Item view.");
    }
}

// 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;    
}
                
</script>
<input type="button" id="GetActiveNamedItem" value="Get Active Named Item" onclick="getActiveNamedItemButton()" />

Applies To

Ewa.Workbook Object

See Also

Concepts

Ewa.Workbook Methods

Ewa Namespace