I've been using Google Sheets API, and following The Google Guide. However there is no example, even beyond the second page of google, to add a worksheet and write to a new sheet in .NET. There is plenty for js, but I have no idea on how to 1) add a sheet or 2) write to a new sheet.
How can I do this? Right now I'm able to read like in the example with out any problems, and I've only found one other reference to v4 C#. I tried going back to v3, but all documents strongly suggest using v4.
Has anyone been able to do this? Here's all I've been able to do so far:
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define request parameters.
// Add new Sheet
string sheetName = string.Format("{0} {1}", DateTime.Now.Month, DateTime.Now.Day);
AddSheetRequest addSheetRequest = new AddSheetRequest();
addSheetRequest.Properties.Title = sheetName;
// How do I tell this to update??
To save someone in the future a headache to end all headaches. I figured out how to add a sheet after hours of trial and error. Still working on how to update values.
Here's how I did it:
Further extending Sam's answer. The following gets me to update a cell.
Hope this helps!
FYI, while the majority of the documentation is just using the raw JSON, it should map 1:1 to the constructs in each language.
For example, to update values you'd likely do something like:
var valueRange = new ValueRange(); valueRange.values = { { 1, 2, 3 }, { 4, 5, 6 } }; var range = "A1"; var update = service.Spreadsheets.Values.Update(valueRange, spreadsheetId, range); var result = update.execute();
The above is pseudo-code based on your code example and the reference docs @ https://developers.google.com/sheets/reference/rest/v4/spreadsheets.values/update.
I have the code to add a sheet as well, but it seems like you figured it out. Here is some code to add content to the sheet. It differs from what others have posted by a little bit, but it should help whoever sees this post.
In this code, it would insert the values of colNames into the row starting at (0,0). So if sheet uses this notation (row, col), then
(0,0)=timestamp
(0,1)=videoid
(0,2)=videoname
(0,3)=firstname
(0,4)=lastname
(0,5)=email
So the whole first row would be filled with the colNames values
I was looking for the Java version of this and I managed to get a working version based on sparky's answer. This should work: