English 中文(简体)
How do I insert a row in to a Google spreadsheet using c#
原标题:

I ve seen; Accessing Google Spreadsheets with C# using Google Data API

and

http://code.google.com/apis/spreadsheets/data/2.0/developers_guide_dotnet.html#CreatingRows

However i m still having trouble inserting a new row in to an existing google spread sheet. Does anyone have a canned example which inserts a List<string> for example in to new row in a spreadsheet workbook.

Many thanks,

最佳回答

Use GDataDB http://github.com/mausch/GDataDB

GDataDB provides a simple way to insert .net POCO entities in to a google spread sheet.

    public void AddToGoogle()
    {
        var client = new DatabaseClient(Settings.Default.GmailAccount, Settings.Default.GmailPassword);
        string dbName = Settings.Default.WorkBook;

        var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
        string tableName = Settings.Default.WorkSheet;

        var t = db.GetTable<ActivityLog>(tableName) ?? db.CreateTable<ActivityLog>(tableName);
        var all = t.FindAll();

        t.Add(this);
    }
问题回答

This Services from Google are discontinued and now they came up with another one named Google.Apis.Sheets.v4 services.

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

And find something that worked out for me.

I have written a blog and shared the whole source code there. Check it out.

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 the entire source code check it out. Insert new row to Google Sheet using Google.Apis.Sheets.V4 Services





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签