Ewa.Workbook.getActiveSheet()

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example
Applies To

Gets the active sheet.

var value = Ewa.Workbook.getActiveSheet();

Return Value

Sheet

Remarks

The Ewa.Workbook.getActiveSheet returns the active sheet in the workbook.

Example

The following code example shows how to add a button to the page and then adds code to the button onClick event that gets a specific range from the active sheet. The code then gets the values within the range and displays them in an alert message.

<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 getRangeFromSheetButton()
{    
    // Get range "B2:C5" from sheet, "mySheet".
    var range = ewa.getActiveWorkbook().getActiveSheet().getRange(1,1,4,2);
    
    // Get values from range.
    range.getValuesAsync(0,getRangeValues,range);    
}

function getRangeValues(asyncResult)
{
    // Get the value from asyncResult if the asynchronous operation was successful.
    if (asyncResult.getCode() == 0)
    {
        // Get range from user context.
        var range = asyncResult.getUserContext();
        
        // Get the array of range values from asyncResult.
        var values = asyncResult.getReturnValue();
        
        // Display range coordinates in A1 notation and associated values.
        var output = "Values from range" + range.getAddressA1() + "\n";
        output = output + "********\n";
        
        // Loop through the array of range values.
        for (var i = 0; i < values.length; i++)
        {
           for (var j = 0; j < values[i].length; j++)
           {
                output= output + values[i][j] + '\n';
           }
        }
        
        output = output + "********";

        // Display each value in the array returned by getValuesAsync.
        alert(output);
    }
    else 
    {
         alert('Operation failed with error message ' + asyncResult.getDescription() + '.');
    }    
}

</script>
<input type="button" id="GetRange" value="Get Range" onclick="getRangeFromSheetButton()" />

Applies To

Ewa.Workbook Object

See Also

Concepts

Ewa.Workbook Methods

Ewa Namespace