【问题标题】:How do I insert a row in to a Google spreadsheet using c#如何使用 C# 在 Google 电子表格中插入一行
【发布时间】:2011-01-12 03:50:10
【问题描述】:

我见过; Accessing Google Spreadsheets with C# using Google Data API

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

但是,我仍然无法在现有的 google 电子表格中插入新行。有没有人有一个罐头示例,例如将List<string> 插入到电子表格工作簿的新行中。

非常感谢,

【问题讨论】:

    标签: c# google-sheets


    【解决方案1】:

    使用 GDataDB http://github.com/mausch/GDataDB

    GDataDB 提供了一种将 .net POCO 实体插入到 google 电子表格中的简单方法。

        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);
        }
    

    【讨论】:

      【解决方案2】:

      Google 的这项服务已停产,现在他们推出了另一个名为 Google.Apis.Sheets.v4 服务的服务。

      所以上面的代码过几天就不行了,我已经试过了。

      然后找到对我有用的东西。

      我写了一个博客并在那里分享了整个源代码。看看吧。

      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;
       }
      

      查看完整的源代码。使用 Google.Apis.Sheets.V4 服务向 Google 表格插入新行

      【讨论】:

      • 您的简历中的链接无效,我对 Google.Apis.Sheets.V4 服务感到非常非常沮丧
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      相关资源
      最近更新 更多