Compartilhar via


Ewa.Sheet.activateAsync(callback, userContext)

Applies to: apps for SharePoint | SharePoint Server 2010

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.

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.

<script type="text/javascript">
     
var ewa = null;
var sheetCount = 1;
     
// 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 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