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)

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

Parameters

sessionId
Type: System.String

The Excel Web Services session ID.

calculateType
Type: Microsoft.Office.Excel.Server.WebServices.CalculateType

Defines the different types (that is, CalculateFull and Recalculate) of workbook calculation.

status
Type: []

Alert information.

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.

//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);
}
  
Show: