ExcelService.OpenWorkbook Method
Opens an Excel workbook file in a new Excel Calculation Services session.
Namespace: Microsoft.Office.Excel.Server.WebServices
Assembly: Microsoft.Office.Excel.Server.WebServices (in Microsoft.Office.Excel.Server.WebServices.dll)
Syntax
'Declaration
<WebMethodAttribute> _
Public Function OpenWorkbook ( _
workbookPath As String, _
uiCultureName As String, _
dataCultureName As String, _
<OutAttribute> ByRef status As Status() _
) As String
'Usage
Dim instance As ExcelService
Dim workbookPath As String
Dim uiCultureName As String
Dim dataCultureName As String
Dim status As Status()
Dim returnValue As String
returnValue = instance.OpenWorkbook(workbookPath, _
uiCultureName, dataCultureName, _
status)
[WebMethodAttribute]
public string OpenWorkbook(
string workbookPath,
string uiCultureName,
string dataCultureName,
out Status[] status
)
Parameters
workbookPath
Type: System.StringThe location of the workbook file to open.
Maximum size is 4096 characters.
uiCultureName
Type: System.StringFollows the Microsoft .NET Framework standard of naming cultures as expressed in the System.Globalization.CultureInfo namespace. Examples of UI culture names: en-US, en-GB, fr-FR, de-DE, ka, ko-KR, ja-JP, hi, , zh-CHS. Use Empty string or Null when not applicable.
dataCultureName
Type: System.StringFollows the Microsoft .NET Framework standard of naming cultures as expressed in the System.Globalization.CultureInfo namespace. Examples of UI culture names: en-US, en-GB, fr-FR, de-DE, ka, ko-KR, ja-JP, hi, zh-CHS. Use Empty string or Null when not applicable.
status
Type: []Alert information.
Return Value
Type: System.String
The sessionId string value.
Remarks
This method opens a new Excel Calculation Services session, opens a workbook file from the given location, and loads it into the session. This method opens a workbook in view mode.
The Excel Web ServicessessionId string is a composite session ID. It is made up of a GUID, a session identity, and the UI Culture.
One example of a sessionId string: 36.00000001-0002-0003-0004-00000000000533.0Zeh6SHf5tN69WBtS|!@en-US|!@en-US
Examples
//Instantiate the Web service and make a status array object
ExcelService es = new ExcelService();
Status[] outStatus;
string sheetName = "Sheet1";
//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
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);
Console.WriteLine("sessionID : {0}", sessionId);
//Close workbook. This also closes session.
es.CloseWorkbook(sessionId);
}