Add row to google spreadsheet

I am trying to add a row to a google spreadsheet. They give the source https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row This source does not work for me, can someone tell me please what is wrong with the lines that include the name "row". "Error 11 The name" string "does not exist in the current context"

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Google.GData.Client; using Google.GData.Spreadsheets; namespace Google_test3 { class Program { static void Main(string[] args) { string USERNAME = "test"; string PASSWORD = "test"; SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1"); service.setUserCredentials(USERNAME, PASSWORD); // Instantiate a SpreadsheetQuery object to retrieve spreadsheets. SpreadsheetQuery query = new SpreadsheetQuery(); // Make a request to the API and get all spreadsheets. SpreadsheetFeed feed = service.Query(query); if (feed.Entries.Count == 0) { Console.WriteLine("None"); } // TODO: Choose a spreadsheet more intelligently based on your // app needs. SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0]; Console.WriteLine(spreadsheet.Title.Text); // Get the first worksheet of the first spreadsheet. // TODO: Choose a worksheet more intelligently based on your // app needs. WorksheetFeed wsFeed = spreadsheet.Worksheets; WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0]; // Define the URL to request the list feed of the worksheet. AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); // Fetch the list feed of the worksheet. ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString()); ListFeed listFeed = service.Query(listQuery); // Create a local representation of the new row. row.Elements.Add(new ListEntry.Custom() { LocalName = "firstname", Value = "Joe" }); row.Elements.Add(new ListEntry.Custom() { LocalName = "lastname", Value = "Smith" }); row.Elements.Add(new ListEntry.Custom() { LocalName = "age", Value = "26" }); row.Elements.Add(new ListEntry.Custom() { LocalName = "height", Value = "176" }); // Send the new row to the API for insertion. service.Insert(listFeed, row); } } } 
+4
source share
2 answers

The documentation below is missing documentation:

 ListEntry row = new ListEntry(); row.Elements.Add(new ListEntry.Custom() { LocalName = "firstname", Value = "Joe" }); row.Elements.Add(new ListEntry.Custom() { LocalName = "lastname", Value = "Smith" }); row.Elements.Add(new ListEntry.Custom() { LocalName = "age", Value = "26" }); row.Elements.Add(new ListEntry.Custom() { LocalName = "height", Value = "176" }); 

If you switch to the Java view, you will see that the Java version includes this line.

+3
source

These services from Google have been discontinued, and now they have come up with another service Google.Apis.Sheets.v4.

so the above code will not work now for several days, I have already tried.

And find something that worked for me.

I wrote a blog and shared all the source code. Check this.

 private static SheetsService AuthorizeGoogleApp() { UserCredential credential; using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Google Sheets API service. var service = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); return service; } 

For all source code, check it out. Paste a new row into Google Sheet using Google.Apis.Sheets.V4 services

+2
source

Source: https://habr.com/ru/post/1411553/


All Articles