Share via


ExcelService.CalculateWorkbook Method

Calculates the entire open workbook, using one of the supported calculation methods.

Namespace:  Microsoft.Office.Excel.Server.WebServices
Assembly:  Microsoft.Office.Excel.Server.WebServices (in Microsoft.Office.Excel.Server.WebServices.dll)

Syntax

'Declaration
<WebMethodAttribute> _
Public Sub CalculateWorkbook ( _
    sessionId As String, _
    calculateType As CalculateType, _
    <OutAttribute> ByRef status As Status() _
)
'Usage
Dim instance As ExcelService
Dim sessionId As String
Dim calculateType As CalculateType
Dim status As Status()

instance.CalculateWorkbook(sessionId, _
    calculateType, status)
[WebMethodAttribute]
public void CalculateWorkbook(
    string sessionId,
    CalculateType calculateType,
    out Status[] status
)

Parameters

  • sessionId
    Type: System.String

    The Excel Web Services session ID.

  • status
    Type: []

    Alert information.

Remarks

The Recalculate type will calculate only those formulas that have been changed.

The CalculateFull type will calculate all formulas, but without rebuilding the dependency tree.

Examples

//Instantiate the Web service 
//and make a status array object.
ExcelService es = new ExcelService();
Status[] outStatus;
string sheetName = "FormulaSheet";

//If workbookPath is a UNC path, the application 
//must be on the same computer as the server.
string targetWorkbookPath = @"\\localhost\xlfiles\Formulas.xlsx";

//Set Credentials for requests
es.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
    //Call open workbook, and point to the trusted 
    //location of the workbook to open.
    string sessionId = es.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);

    //Recalculate the workbook.
    es.CalculateWorkbook(sessionId, CalculateType.Recalculate);

    //Close workbook. This also closes the session.
    es.CloseWorkbook(sessionId);
}
  

See Also

Reference

ExcelService Class

ExcelService Members

Microsoft.Office.Excel.Server.WebServices Namespace