C# Google API (SheetsServices) Insert new row -


how can insert new row google spreadsheet.

using google api (sheetsservices).

class googleapi     {         // if modifying these scopes, delete saved credentials         // @ ~/.credentials/sheets.googleapis.com-dotnet-quickstart.json         static string[] scopes = { sheetsservice.scope.spreadsheets, "email" };         static string applicationname = "google sheets api .net quickstart";          public googleapi()         {             usercredential credential;              using (var stream =                 new filestream("secret.json", filemode.open, fileaccess.read))             {                 string credpath = system.environment.getfolderpath(                     system.environment.specialfolder.personal);                 credpath = path.combine(credpath, ".credentials/secret.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 plus api service.             var plusservice = new plusservice(new baseclientservice.initializer()             {                 httpclientinitializer = credential,                 applicationname = applicationname,             });              // create google sheets api service.             var service = new sheetsservice(new baseclientservice.initializer()             {                 httpclientinitializer = credential,                 applicationname = applicationname,             });              var me = plusservice.people.get("me").execute();             var useremail = me.emails.firstordefault().value;         }     } 

up part, have able

  • authenticate user using oauth2
  • getting email allow access

the problem: how can insert new row, in sheets.

additional question: possible bind linq spreadsheet?

after trying little bit while waiting answer, realize answer. i'm gonna post here others.

            ilist<object> obj = new list<object>();             obj.add("a2");             obj.add("b2");             ilist<ilist<object>> values = new list<ilist<object>>();             values.add(obj);              spreadsheetsresource.valuesresource.appendrequest request =                     service.spreadsheets.values.append(new valuerange() { values = values }, spreadsheetid, range);             request.insertdataoption = spreadsheetsresource.valuesresource.appendrequest.insertdataoptionenum.insertrows;             request.valueinputoption = spreadsheetsresource.valuesresource.appendrequest.valueinputoptionenum.raw;             var response = request.execute(); 

the .insertdataoption 1 allowing added new row.

the .valueinputoption required, @ first didn't set , error comes out.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -