Ewa.Sheet.getRangeA1Async(addressA1, callback, userContext)

Last modified: June 14, 2011

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example

Gets the specified range in the open workbook asynchronously using the Excel "A1" range notation as an input parameter.

Ewa.Sheet.getRangeA1Async(addressA1, callback, userContext);

addressA1

The range to get in A1 notation.

callback

The function that is called when the request is completed.

userContext

An object provided as a way for callers to pass state through the asynchronous call.

The Ewa.Sheet.getRangeA1Async method gets a range asynchronously by using A1 notation as one of the input parameters. For example A4:B9, which specifies a range located on the specified worksheet that begins at cell A4 and extends to cell B9.

Note Note

The string supplied for addressA1 should not include the sheet name as the sheet is assumed to be the sheet object that calls Ewa.Sheet.getRangeA1Async. If the sheet name is specified, the AsyncResult.getReturnValue method will return null.

Note Note

Ewa.Sheet.getRangeA1Async cannot generate a range on a chart sheet.

The following code example shows how to add a button and a text input box to the page and then adds code to the button onClick event that takes the range address entered into the text box (in A1 notation) and activates the specified range.

<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 getRangeA1Button()
{
    // Get the A1 address entered.
    var a1Address = document.forms.aspnetForm.GetRangeAddress.value;
    
    // Call getRangeA1Async with the A1 address entered.
    ewa.getActiveWorkbook().getActiveSheet().getRangeA1Async(a1Address, getRangeA1Callback, null);    
}

function getRangeA1Callback(asyncResult)
{
    // getRangeA1Async returns a range object through the AsyncResult object.
    var range = asyncResult.getReturnValue();
    
    // Activate the range that the user entered.
    // Pass in range as user context so it can be used in callback.
    range.activateAsync(0,2,activateAsyncCallback,range);    
}

function activateAsyncCallback(asyncResult)
{
    // activateAsync does not return a range through AsyncResult so 
    // get the range from the user context passed in with activateAsync call.
    var range = asyncResult.getUserContext();
    
    // Display which address for which range was activated.
    window.status = "Range located at A1 address: " + range.getAddressA1() + " was activated.";
}

</script>
<input type="button" id="GetRange" VALUE="Get Range" onclick="getRangeA1Button()">
<input type="text" id="GetRangeAddress" value="Enter A1 Address">


Show: