ExcelService.SetCell Method

Sets a value or formula into a cell.

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

public void SetCell(
	string sessionId,
	string sheetName,
	int row,
	int column,
	Object cellValue,
	out Status[] status


Type: System.String

The Excel Web Services session ID.

Type: System.String

The name of the sheet that you want to reference. Sheet name length is limited to 31 characters.

Type: System.Int32

Cell's row, 0-based.

Type: System.Int32

Cell's column, 0-based.

Type: System.Object

Value for the cell being set.

Type: []

Alert information.

Sets a value (number or text) or formula into a cell in the open workbook, using numeric cell coordinates to select the range. Setting a value or a formula into a cell replaces the previous value or formula, but does not affect the formatting of the cell.

Setting a formula into a cell requires open item or edit item permissions and is supported in view and edit mode. You will get a formula editing not enabled alert if you attempt to set a formula into a cell in view mode with only view item permission.

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.

//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;

        //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.
    catch (SoapException e)
        Console.WriteLine("Exception Message: {0}", e.Message);