Ewa.Sheet.getRange(firstRow, firstColumn, rowCount, columnCount)

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example

Gets the specified range in the open workbook by using numeric range coordinates in R1C1 range notation.

var value = Ewa.Sheet.getRange(firstRow, firstColumn, rowCount, columnCount);

Parameters

firstRow

The initial row position of the range.

firstColumn

The initial column position of the range.

rowCount

The number of rows to include in the range.

columnCount

The number of columns to include in the range.

Return Value

range

Remarks

The Ewa.Sheet.getRange method returns a range specified as the initial row and column positions and the number of rows and columns to include in the range.

Note

Ewa.Sheet.getRange cannot generate a range on a chart 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 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 the active sheet.
    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()" />

See Also

Reference

Ewa.Sheet Object