Hello!
For a project I have been working on I need to update a Google Sheet. I’m using the Google.Apis.Sheets NuGet package
(JavaScript quickstart | Google Sheets | Google for Developers).
To update cells in a sheet, you make an instance of Google.Apis.Sheets.v4.Data.ValueRange(), like so:
let valueRange = new Google.Apis.Sheets.v4.Data.ValueRange()
And then you set the value property:
valueRange.Values <- values
The problem is that Values
expects a Collections.Generic.IList<Collections.Generic.IList<obj>>
, and I can not figure out what’s really expected (since it’s an interface). The API documentation says the following:
The data that was read or to be written. This is an array of arrays, the outer array representing all the data and each inner array representing a major dimension. Each item in the inner array corresponds with one cell.
For output, empty trailing rows and columns will not be included.
For input, supported value types are: bool, string, and double. Null values will be skipped. To set a cell to an empty value, set the string value to an empty string.
No help there. The only way I found to set the values is to use an array directly (which will be too tedious and impracticable to do):
valueRange.Values <- [| [|"cell1"; "cell2"|]|]
What’s interesting is that this does not work:
let values = [| [|"cell1"; "cell2"|]|]
valueRange.Values <- values
It gives the following error:
The type 'Collections.Generic.IList<obj>' does not match the type 'string []'
Not sure if this is relevant, but in C# one can set the property like this:
var values = new List<object>() { "cell1" };
valueRange.Values = new List<IList<object>> { values };
Can someone please shed some light on this issue? It would be highly appreciated!