Ewa.Sheet.activateAsync(callback, userContext)

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

In this article
Return Value
Remarks
Example

Activates the sheet or chart sheet.

Ewa.Sheet.activateAsync(callback, userContext);

Parameters

callback

The function that is called when the request is complete.

userContext

An object provided as a way for callers to pass state through the asynchronous call.

Return Value

None.

Remarks

The Ewa.Sheet.activateAsync method activates the specified sheet.

Important

If the sheet that is activated is a Power View sheet, the sheet will be activated, but the specified callback for Ewa.Sheet.activateAsync will not be called.

Example

The following code example shows how to add a button to the page and then adds code to the button onClick event that activates the next sheet in the workbook using the Ewa.Sheet.activateAsync method and then displays the sheet name in the browser status bar. Each button click activates the next sheet in the collection of sheets until the last sheet has been activated at which point the next click begins at the first sheet in the collection. 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;
var sheetCount = 1;
     
// 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 activateSheetButton()
{    
    // Get a reference to the workbook.
    var wkBook = ewa.getActiveWorkbook();    
        
    
    // Get the collection of sheets in the workbook.
    var sheets = wkBook.getSheets();
    
    // Get the next sheet.
        var sheet = sheets.getItem(sheetCount);
                
    sheetCount++;
    
    // If at the end of the sheets collection, start over.
    if (sheetCount >= sheets.getCount())
    {
        sheetCount = 0;
    } 
           
    // Activate the specified sheet.
    // Pass in sheet as user context.
    sheet.activateAsync(activateSheetCallBack, sheet);    
}

      
function activateSheetCallBack(asyncResult)
{  
    // Get the activated sheet from user context.
    var activatedSheet = asyncResult.getUserContext();
    
    // Display name of activated sheet in browser status bar.
    window.status = "Sheet " + activatedSheet.getName() + " was activated.";    
}

</script>
<input type="button" id="ActivateSheet" value="Activate Sheet" onclick="activateSheetButton()" />

See also

Reference

Ewa.Sheet Object