共用方式為


Ewa.Workbook.getActiveCell()

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example
Applies To

Gets the active cell as a range object.

var value = Ewa.Workbook.getActiveCell();

Return Value

range

Remarks

The Ewa.Workbook.getActiveCell method returns the active cell as a range. Ewa.Workbook.getActiveCell returns null if a chart or a chart sheet is active, if no cell on the Excel Services Excel Web Access Web Part grid is active, or if the Excel Services Excel Web Access Web Part is in named item view and the active cell is outside the published item.

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 unformatted value in the active cell 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 getRangeValuesButton()
{
    // Get unformatted range values (getValuesAsync(0,...) where 0 = ValuesFormat.Unformatted)
    ewa.getActiveWorkbook().getActiveCell().getValuesAsync(0,getRangeValues,null);
}     

function getRangeValues(asyncResult)
{
    // Get the value from asyncResult if the asynchronous operation was successful.
    if (asyncResult.getCode() == 0)
    {
        // Get the value in active cell (located at row 0, column 0 of the 
        // range which consists of a single cell (the "active cell")).
        window.status = asyncResult.getReturnValue()[0][0];
    }
    else 
    {
         alert("Operation failed with error message " + asyncResult.getDescription() + ".");
    }    
} 

</script>
<input type="button" id="GetRangeValues" value="Get Range Values" onclick="getRangeValuesButton()" />

Applies To

Ewa.Workbook Object

See Also

Concepts

Ewa.Workbook Methods

Ewa Namespace