Ewa.Range.getValuesAsync(format, callback, userContext)

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example

Gets a two-dimensional array object that represents the values in the specified range.

Ewa.Range.getValuesAsync(format, callback, userContext);

Parameters

format

An Ewa.ValuesFormat Enumeration constant.

callback

The function that is called when the asynchronous operation is completed.

userContext

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

Return Value

None

Remarks

The callback method specified in Ewa.Range.getValuesAsync returns a two-dimensional array object with associated values through the AsyncResult argument that was passed in to the call to the callback method. If Ewa.ValuesFormat.Unformatted is specified, the values returned are unformatted. If Ewa.ValuesFormat.Formatted is specified, the callback method returns localized formatted values.

Important

Ewa.Range.getValuesAsync is limited to ranges of 10,000 or less cells. If more than 10,000 cells are requested, the callback method returns an Ewa.AsyncErrorCode.RangeSizeError error code.

Example

The following code example shows how to add a button to the page and then adds an event handler to the button onClick event that displays the unformatted value in the active cell in the browser status bar. This code example shows how to retrieve a single value from the array that is returned by Ewa.Range.getValuesAsync.

<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 getRangeValuesButton()
{
    // Get unformatted range values (getValuesAsync(0,...) where 0 = ValuesFormat.Unformatted)
    ewa.getActiveWorkbook().getActiveCell().getValuesAsync(0,getRangeValues,null);
}     

function getRangeValues(asyncResult)
{
    // Get the value from asyncResult if the asynchronous operation was successful.
    if (asyncResult.getCode() == 0)
    {
        // Get the value in active cell (located at row 0, column 0 of the
        // range which consists of a single cell (the "active cell")).
        window.status = asyncResult.getReturnValue()[0][0];
    }
    else 
    {
         alert("Operation failed with error message " + asyncResult.getDescription() + ".");
    }    
} 

</script>
<input type="button" id="GetRangeValues" value="Get Range Values" onclick="getRangeValuesButton()" />

The following code example uses mostly the same code as in the previous example, but shows how to retrieve values from a range that consists of multiple cells. The values are displayed in a single 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 getRangeValuesButton()
{
    // Get unformatted range values (getValuesAsync(0,...) where 0 = ValuesFormat.Unformatted)
    ewa.getActiveWorkbook().getActiveSelection ().getValuesAsync(0,getRangeValues,null);
}     

function getRangeValues(asyncResult)
{
    // Get the value from asyncResult if the asynchronous operation was successful.
    if (asyncResult.getCode() == 0)
    {
        // Get the array of range values from asyncResult.
        var values = asyncResult.getReturnValue();
        var output = '';
        
        // 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';
           }
        }

        // 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="GetRangeValues" value="Get Range Values" onclick="getRangeValuesButton()" />

See Also

Reference

Ewa.Range Object