ExcelService.CloseWorkbook Method

Closes the session and the workbook that is currently open in that session.

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

[WebMethodAttribute]
public void CloseWorkbook(
	string sessionId,
	out Status[] status
)

Parameters

sessionId
Type: System.String

The Excel Web Services session ID.

status
Type: []

Alert information.

This method closes the workbook that is currently loaded in the session.

The Excel Calculation Services session associated with the workbook also will close. When you are done using the session, close the workbook. This closes the session and frees resources.

//Instantiate the web service and make a status array object
ExcelService xlservice = new ExcelService();
Status[] outStatus;

//Using workbookPath this way will allow 
//you to call the workbook remotely.
string targetWorkbookPath = "http://myserver02/example/Shared%20Documents/Book1.xlsx";

//Set Credentials for requests
xlservice.Credentials = System.Net.CredentialCache.DefaultCredentials;

try
{
//Call open workbook, and point to the trusted   
//location of the workbook to open.
string sessionId = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);

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

Show: