Ewa.SheetCollection.getItem(index)

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example
Applies To

Gets the nth sheet.

var value = Ewa.SheetCollection.getItem(index);

Parameters

index

An integer value that specifies the ordinal position of the sheet in the sheets collection.

Return Value

sheet

Remarks

The Ewa.SheetCollection.getItem method returns the specified sheet using the index value of the sheet. The index is zero-based. Returns null if the nth sheet does not exist.

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 button click activates a sheet beginning 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()" />

Applies To

Ewa.SheetCollection Object

See Also

Concepts

Ewa.SheetCollection Methods

Ewa Namespace