Ewa.Workbook.getRange(parentName, firstRow, firstColumn, rowCount, columnCount)

Last modified: September 15, 2011

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example

Gets the specified range using a sheet name and the numeric range coordinates using R1C1 notation.

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

parentName

The name of the sheet where the range is located.

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.

The Ewa.Workbook.getRange method returns a range specified as a sheet, the initial row and column positions, and the number of rows and columns to include in the range. If the name of the sheet is omitted, then parentName must either be set to an empty string or to null.

Note Note

The coordinate positions are zero-based. For example, to specify an initial range position, A1, you set the coordinate row and column positions to 0 and 0, respectively.

Depending upon the view mode, Ewa.Workbook.getRange must be called in different ways:

  • Named Item view. firstRow and firstColumn refer to the row and column of the named item (and not those of the underlying sheet) when a named item name is passed in as an argument for parentName. If specified cells are outside of the named item range, Ewa.Workbook.getRangereturns null

  • Sheet view. parentName must be set to null, empty string, or the name of a sheet. parentName cannot be the name of a named item. If parentName is null, then the range will be on the currently active sheet.

Note Note

Ewa.Workbook.getRange cannot generate a range on a chart sheet.

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 range from the specified 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 "Sheet2".
    var range = ewa.getActiveWorkbook().getRange("Sheet2",1,1,4,2);
    
    // Get values from range.
    range.getValuesAsync(Ewa.ValuesFormat.Unformatted,getRangeValues,range);    
}

function getRangeValues(asyncResult)
{
    // Get the value from asyncResult if the asynchronous operation was successful.
    if (asyncResult.getCode() == Ewa.AsyncErrorCode.Successful)
    {
        // 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()" />
Show: