Last modified: October 03, 2012

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

In this article
Return Value

Gets the Ewa.EwaControl object that represents the embedded Microsoft Excel workbook on the host page.

var value = Ewa.AsyncResult.getEwaControl();

The [AsyncResult] object is passed as an argument to the callback specified in the asynchronous method call. The [AsyncResult.getEwaControl] method enables you to get a reference to the embedded workbook on the host web page.

The following code example shows how to work programmatically with an embedded Excel workbook by using the ECMAScript (JavaScript, JScript) API. The code uses the [AsyncResult.getEwaControl] method to get a reference to the embedded workbook.

<div id="myExcelDiv" style="width: 402px; height: 346px"></div>
<script type="text/javascript" src="http://r.office.microsoft.com/r/rlidExcelWLJS?v=1&kip=1"></script>
<script type="text/javascript">
    * This code uses the Microsoft Office Excel JavaScript object model to programmatically insert the
    * Excel Web App into a div with id=myExcelDiv. The full API is documented at
    * http://msdn.microsoft.com/en-us/library/hh315812.aspx. There you can find out how to get
    * values programmatically from your Excel file and how to use the rest of the object model. 

    // Use this file token to reference Book1.xlsx in the Excel APIs.
    var fileToken = "SD310A16DD64ED7E41!112/3533661997762444865/";
    var ewa = null;

    // Run the Excel load handler on page load.
    if (window.attachEvent)
        window.attachEvent("onload", loadEwaOnPageLoad);
    } else
        window.addEventListener("DOMContentLoaded", loadEwaOnPageLoad, false);

    function loadEwaOnPageLoad()
        var props = {
            uiOptions: {
                showGridlines: false,
                showRowColumnHeaders: false,
                showParametersTaskPane: false
            interactivityOptions: {
                allowTypingAndFormulaEntry: false,
                allowParameterModification: false,
                allowSorting: false,
                allowFiltering: false,
                allowPivotTableInteractivity: false
        // Embed workbook using loadEwaAsync.
        Ewa.EwaControl.loadEwaAsync(fileToken, "myExcelDiv", props, onEwaLoaded);

    function onEwaLoaded(asyncResult)
        if (asyncResult.getSucceeded())
            // Use the AsyncResult.getEwaControl() method to get a reference to the EwaControl object.
            ewa = asyncResult.getEwaControl();
            alert("Async operation failed!");
        // ...

    // Handle the active cell changed event.
    function cellChanged(rangeArgs)
        // Use the RangeEventArgs object to get information about the range.
        var sheetName = rangeArgs.getRange().getSheet().getName();
        var col = rangeArgs.getRange().getColumn();
        var row = rangeArgs.getRange().getRow();
        var value = rangeArgs.getFormattedValues();
        alert("The active cell is located at row " + (row + 1) + " and column " + (col + 1) + " with value '" + value + "'.");
        // ...