Export (0) Print
Expand All

Ewa.Workbook.getActiveSelection()

Last modified: June 14, 2011

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example
Applies To

Gets the current selection as a range object.

var value = Ewa.Workbook.getActiveSelection();

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.

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.

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

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

function getEwa()
{        
    // 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()" />
Show:
© 2015 Microsoft