Ewa.Sheet.getName()
Applies to: apps for SharePoint | SharePoint Server 2010
In this article
Return Value
Remarks
Example
Applies To
Gets the name of the sheet or chart sheet.
var value = Ewa.Sheet.getName();
Return Value
string
Remarks
The Ewa.Sheet.getName method returns the name of the specified sheet as a string.
Example
The following code example shows how to add a button to the page and then adds code to the button onClick event that activates the next sheet in the workbook using the Ewa.Sheet.activateAsync method and then displays the sheet name in the browser status bar using the Ewa.Sheet.getName method. Each button click activates the next sheet in the collection of sheets until the last sheet has been activated at which point the next click begins at the first sheet in the collection.
<script type="text/javascript">
var ewa = null;
var sheetCount = 1;
// 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 activateSheetButton()
{
// Get a reference to the workbook.
var wkBook = ewa.getActiveWorkbook();
// Get the collection of sheets in the workbook.
var sheets = wkBook.getSheets();
// Get the next sheet.
var sheet = sheets.getItem(sheetCount);
sheetCount++;
// If at the end of the sheets collection, start over.
if (sheetCount >= sheets.getCount())
{
sheetCount = 0;
}
// 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()" />