Ewa.Workbook.getActiveSelection()

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

In this article
Return Value
Remarks
Example
Applies To

Gets the current selection as an Ewa.Range object.

var value = Ewa.Workbook.getActiveSelection();

Return Value

Type: Ewa.Range

Remarks

The [Ewa.Workbook.getActiveSelection] method returns the current selection as a range. [Ewa.Workbook.getActiveSelection] returns null if no cell or cells on the grid are selected.

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 column position of the selected range 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 getRangeColumnButton()
{
    // Get the active range.
    var range = ewa.getActiveWorkbook().getActiveSelection();
    
    if (range != null)
    {
    // Display range column number.
    window.status = "Column number of range: " + range.getColumn(); 
    }    
    else
    {
       alert("No range selected.");
    }    
}            
</script>
<input type="button" id="ShowRangeColumn" value="Show Range Column" onclick="getRangeColumnButton()" />

Applies To

Ewa.Workbook Object

See also

Concepts

Ewa.Workbook Methods

Ewa namespace