Ewa.Workbook.getActiveSheet()
Applies to: apps for SharePoint | Excel Services | SharePoint Server 2013
In this article
Return Value
Remarks
Example
Applies To
Gets the active Ewa.Sheet.
var value = Ewa.Workbook.getActiveSheet();
Return Value
Type: Ewa.Sheet
Remarks
The [Ewa.Workbook.getActiveSheet] returns the active sheet in the workbook.
Example
The following code example shows how to add a button to the page and then adds code to the button onClick event that gets a specific range from the active sheet. The code then gets the values within the range and displays them in an alert message. 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 getRangeFromSheetButton()
{
// Get range "B2:C5" from sheet, "mySheet".
var range = ewa.getActiveWorkbook().getActiveSheet().getRange(1,1,4,2);
// Get values from range.
range.getValuesAsync(0,getRangeValues,range);
}
function getRangeValues(asyncResult)
{
// Get the value from asyncResult if the asynchronous operation was successful.
if (asyncResult.getCode() == 0)
{
// Get range from user context.
var range = asyncResult.getUserContext();
// Get the array of range values from asyncResult.
var values = asyncResult.getReturnValue();
// Display range coordinates in A1 notation and associated values.
var output = "Values from range" + range.getAddressA1() + "\n";
output = output + "********\n";
// Loop through the array of range values.
for (var i = 0; i < values.length; i++)
{
for (var j = 0; j < values[i].length; j++)
{
output= output + values[i][j] + '\n';
}
}
output = output + "********";
// Display each value in the array returned by getValuesAsync.
alert(output);
}
else
{
alert('Operation failed with error message ' + asyncResult.getDescription() + '.');
}
}
</script>
<input type="button" id="GetRange" value="Get Range" onclick="getRangeFromSheetButton()" />