Share via


Ewa.SheetCollection.getCount()

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

In this article
Return Value
Remarks
Example
Applies To

Gets the count of sheets in a workbook.

var value = Ewa.SheetCollection.getCount();

Return Value

Type: integer

Remarks

The Ewa.SheetCollection.getCount method returns the number of sheets in the workbook. The count of sheets includes worksheets and chart sheets.

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 total count of sheets in the workbook 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);                                   
}              

// Add event handler for button onClick event.
function getSheetCountButton()
{
    // Get the Sheets collection.
    var sheets = ewa.getActiveWorkbook().getSheets();

    // Display count of sheets in workbook.
    alert("There are " + sheets.getCount() + " sheets.");    
}

</script>
<input type="button" id="GetSheetCount" value="Get Sheet Count" onclick="getSheetCountButton()" /> 

Applies To

Ewa.SheetCollection Object

See also

Concepts

Ewa.SheetCollection Methods

Ewa namespace