Share via


ExcelService.SetCell Method

Sets a value into a cell.

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

Syntax

'Declaration
<WebMethodAttribute> _
Public Sub SetCell ( _
    sessionId As String, _
    sheetName As String, _
    row As Integer, _
    column As Integer, _
    cellValue As Object, _
    <OutAttribute> ByRef status As Status() _
)
'Usage
Dim instance As ExcelService
Dim sessionId As String
Dim sheetName As String
Dim row As Integer
Dim column As Integer
Dim cellValue As Object
Dim status As Status()

instance.SetCell(sessionId, sheetName, _
    row, column, cellValue, status)
[WebMethodAttribute]
public void SetCell(
    string sessionId,
    string sheetName,
    int row,
    int column,
    Object cellValue,
    out Status[] status
)

Parameters

  • sessionId
    Type: System.String
    The Excel Web Services session ID.
  • sheetName
    Type: System.String
    The name of the sheet you want to reference. Sheet name length is limited to 31 characters.
  • status
    Type: []
    Alert information.

Remarks

Sets a value into a cell in the open workbook, using numeric cell coordinates to select the range. If you are setting values to multiple adjacent cells, you may want to consider using the SetRange method instead of making multiple calls to the SetCell method. This would result in a single roundtrip to the server instead of multiple roundtrips. It may also result in fewer calculation steps. Therefore, in some cases, you may gain a noticeable performance improvement by using the SetRange method instead of the SetCell method.

Examples

//Instantiate the Web service and make a status array object
ExcelService xlservice = 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
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);

        //Set the cell in the first row, tenth column, to 200
        xlservice.SetCell(sessionId, sheetName, 0, 9, 200);

        //Close workbook. This also closes session.
        xlservice.CloseWorkbook(sessionId);
    }
    catch (SoapException e)
    {
        Console.WriteLine("Exception Message: {0}", e.Message);
    }

See Also

Reference

ExcelService Class

ExcelService Members

Microsoft.Office.Excel.Server.WebServices Namespace