Home >Backend Development >Golang >How to Write and Update Google Sheets Data with Go (API V4)?
Writing and Updating Google Sheets Data with Go (API V4)
When attempting to write data to a Google Sheet using the Golang library, the absence of clear examples can be frustrating. Here's a straightforward solution, using a modified version of the main function from the official quick start guide:
<code class="go">func write() { // Required OAuth2 setup (see quick start guide for details) srv, err := sheets.New(client) if err != nil { log.Fatalf("Unable to retrieve Sheets Client %v", err) } spreadsheetId := "YOUR_SPREADSHEET_ID" writeRange := "A1" var vr sheets.ValueRange // Example data to be written (here: three columns) myval := []interface{}{"One", "Two", "Three"} vr.Values = append(vr.Values, myval) _, err = srv.Spreadsheets.Values.Update(spreadsheetId, writeRange, &vr).ValueInputOption("RAW").Do() if err != nil { log.Fatalf("Unable to update sheet data %v", err) } }</code>
In this modified main function:
The above is the detailed content of How to Write and Update Google Sheets Data with Go (API V4)?. For more information, please follow other related articles on the PHP Chinese website!