Share via


Ewa.Workbook.getActiveCell()

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

In this article
Return Value
Remarks
Example
Applies To

Gets the active cell as an Ewa.Range object.

var value = Ewa.Workbook.getActiveCell();

Return Value

Type: Ewa.Range

Remarks

The [Ewa.Workbook.getActiveCell] method returns the active cell as a range. [Ewa.Workbook.getActiveCell] returns null if a chart or a chart sheet is active, if no cell is active, or if the display is in named item view and the active cell is outside the published item.

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. The code example assumes that you are working with an Excel Web Access Web Part 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 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()" />

Applies To

Ewa.Workbook Object

See also

Concepts

Ewa.Workbook Methods

Ewa namespace