How to update value of a cell that have a Hyperlink by Smartsheeet API C# SDK?

713 views Asked by At

We have to update value of a smartsheet Cell. This Cell contains Hyperlink to a different sheet. Hyperlink URL is assigned. We want to update this cell value by Smartsheet API C# SDK.

1

There are 1 answers

0
Kim Brandl On

If I'm understanding your scenario correctly, a cell in your sheet contains a hyperlink to another Smartsheet sheet (as described here), and you want to update that cell value to be a hyperlink that points to a different sheet in Smartsheet. The following code uses the Smartsheet C# SDK to accomplish that.

// Replace the second parameter here with your API Access Token
System.Environment.SetEnvironmentVariable("SMARTSHEET_ACCESS_TOKEN", "replace-this-string-with-your-API-access-token");

SmartsheetClient smartsheet = new SmartsheetBuilder().Build();

// Specify updated cell value (hyperlink to another sheet)
var cellToUpdate = new Cell
{
    ColumnId = 6101753539127172,  // ID of the column that contains the cell you're updating
    Value = "text-value-for-hyperlink",  // text value of hyperlink to display in the cell -- typically set to the target Sheet's name
    Hyperlink = new Hyperlink
    {
        SheetId = 7501762300012420  // ID of the sheet that the hyperlink will point to
    }
};

// Identify row and add updated cell object to it
var rowToUpdate = new Row
{
    Id = 4324392993613700,  // ID of the row that contains the cell you're updating
    Cells = new Cell[] { cellToUpdate }
};

// Issue the 'update row(s)' request
IList<Row> updatedRow = smartsheet.SheetResources.RowResources.UpdateRows(
    3932034054809476,    // ID of the sheet that you're updating
    new Row[] { rowToUpdate }
);

Hopefully this is helpful. If I'm not understanding your scenario correctly, please comment on this answer to elaborate further about your scenario.

** UPDATE - replacing the sheet hyperlink with another type of value **

Please note, if you want to remove the sheet hyperlink from the cell and replace it with another value, you should specify an empty Hyperlink object in the request, as shown in the following code.

// Specify updated cell value (just a text value -- i.e., no longer a sheet hyperlink)
var cellToUpdate = new Cell
{
    ColumnId = 6101753539127172,  // ID of the column that contains the cell you're updating
    Value = "new-cell-value",
    Hyperlink = new Hyperlink()
};