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)
Syntax
'Declaration
<WebMethodAttribute> _
Public Sub CloseWorkbook ( _
sessionId As String, _
<OutAttribute> ByRef status As Status() _
)
'Usage
Dim instance As ExcelService
Dim sessionId As String
Dim status As Status()
instance.CloseWorkbook(sessionId, status)
[WebMethodAttribute]
public void CloseWorkbook(
string sessionId,
out Status[] status
)
Parameters
- sessionId
Type: System.String
The Excel Web Services session ID.
- status
Type: []
Alert information.
Remarks
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, it is good practice to close the workbook. This closes the session and frees resources.
Examples
//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);
}