Ewa.Workbook.getActiveNamedItem()

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

In this article
Return Value
Remarks
Example
Applies To

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

var value = Ewa.Workbook.getActiveNamedItem();

Return Value

Type: Ewa.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. The code example assumes that you are working with an Excel Web Access Web Part 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);                                   
}              
        
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