Share via


Ewa.Range.setValuesAsync(values, callback, userContext)

Applies to: apps for SharePoint | Excel Services | SharePoint Server 2013

In this article
Return Value
Remarks
Example

Sets the values for a two-dimensional array object.

Ewa.Range.setValuesAsync(values, callback, userContext);

Parameters

values

A two-dimensional jagged array that contains the values that you want to set.

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 Ewa.Range.setValuesAsync method sets the values for a specified range. You set the values using a jagged array (an array of arrays) that specifies the row/column of the cell(s). Setting cell values is not permitted in view mode, regardless of permissions.

Important

Ewa.Range.setValuesAsync is limited to ranges of 10,000 or less cells. If more than 10,000 cells are set, 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 sets the values for the specified range. In this example, Ewa.Range.setValuesAsync sets the values for a range selection that consists of 3 rows by 2 columns.

Note

For the following example to complete properly, the Excel Web Access Web Part must have Typing and Formula Entry enabled (in Excel Web Access properties, Navigation and Interactivity, Interactivity:) and values must be equal to the size of the range being set. The code example assumes that you are working with Excel Web Access Web Parts on SharePoint Server 2013.

<script type="text/javascript">
 
var ewa = null;
 
// Add event handler for onload event.
if (window.attachEvent) 
{ 
    window.attachEvent("onload", ewaOnPageLoad);    
} 
else 
{ 
    window.addEventListener("DOMContentLoaded", ewaOnPageLoad, false); 
}

// Add event handler for applicationReady event.
function ewaOnPageLoad() 
{ 
Ewa.EwaControl.add_applicationReady(onApplicationReady); 
} 

function onApplicationReady()
{        
    // Get a reference to the Excel Services Web Part.
    ewa = Ewa.EwaControl.getInstances().getItem(0);                                     
}  

function setRangeValuesButton()
{
    // Get a reference to the active selection as a range.
    var selection = ewa.getActiveWorkbook().getActiveSelection();
    
    // Set up the values that will be set in the call to setValuesAsync.
    var values = new Array(3);
    
    // Create a 2 dimensional array with 3 array elements,
    // where each element represents a row in the range.
    values[0] = new Array(2);
    values[1] = new Array(2);
    values[2] = new Array(2);
    
    // Set values for the first element.
    values[0][0] = "one";
    values[0][1] = "two";
    
    // Set values for the second element.
    values[1][0] = "three";
    values[1][1] = "four";
    
    // Set values for the third element.
    values[2][0] = "five";
    values[2][1] = "six";
    
    // Call setValuesAsync to set the values.
    selection.setValuesAsync(values,setRangeValues,null);
}     

function setRangeValues(asyncResult)
{
    window.status = "Set values completed: " + asyncResult.getSucceeded();
}
       

</script>
<input type="button" id="SetRangeValues" value="Set Range Values" onclick="setRangeValuesButton()" />

See also

Reference

Ewa.Range Object