Ewa.SheetCollection.getItemByName(name)
Applies to: apps for SharePoint | Excel Services | SharePoint Server 2013
In this article
Return Value
Remarks
Example
Applies To
Gets the Ewa.Sheet with the matching name.
var value = Ewa.SheetCollection.getItemByName(name);
Parameters
name
The display name of the worksheet.
Return Value
Type: Ewa.Sheet
Remarks
The Ewa.SheetCollection.getItemByName method returns the specified sheet using its display name.
Example
The following code example shows how to add a button to the page and then adds an event handler for the button onClick event that activates a worksheet, "Sheet3", using its display name and then displays the worksheet name 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 activateSheetButton()
{
// Get a reference to the workbook.
var wkBook = ewa.getActiveWorkbook();
// Get the collection of named items in the workbook.
var sheets = wkBook.getSheets();
// Get the next sheet
var sheet = sheets.getItemByName('Sheet3');
// Activate the specified sheet.
// Pass in sheet as user context.
sheet.activateAsync(activateSheetCallBack, sheet);
}
function activateSheetCallBack(asyncResult)
{
// Get the activated sheet from user context.
var activatedSheet = asyncResult.getUserContext();
// Display name of activated sheet in browser status bar.
window.status = "Sheet " + activatedSheet.getName() + " was activated.";
}
</script>
<input type="button" id="ActivateSheet" value="Activate Sheet" onclick="activateSheetButton()" />