次の方法で共有


Ewa.AsyncResult.getEwaControl()

**適用対象:**apps for SharePoint | Excel Services | SharePoint Server 2013

この記事の内容
戻り値
注釈

[Host] ページでMicrosoft Excelの埋め込まれたブックを表す**Ewa.EwaControl**オブジェクトを取得します。

var value = Ewa.AsyncResult.getEwaControl();

戻り値

[Type]: Ewa.EwaControl

注釈

**[AsyncResult]オブジェクトは、非同期メソッドの呼び出しで指定されたコールバックに引数として渡されます。[AsyncResult.getEwaControl]**メソッドを使用すると、ホストの web ページに埋め込まれたブックへの参照を取得することができます。

次の例では、 ECMAScript (JavaScript, JScript) API を使用して、埋め込まれたExcelブックを作成するプログラムから操作する方法を示します。コードでは、 **[AsyncResult.getEwaControl]**メソッドを使用して、埋め込まれたブックへの参照を取得します。

<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
    * https://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();
            ewa.add_activeCellChanged(cellChanged);
        }
        else
        {
            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 + "'.");
        // ...
    }
</script>

関連項目

参照先

Ewa.AsyncResult 方法

概念

Ewa 名前空間