c# - 在谷歌电子表格中添加一行

标签 c# row add google-spreadsheet-api

我正在尝试向谷歌电子表格中添加一行。他们给了一个来源https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row但是这个来源对我不起作用任何人都可以告诉我包含名称“行”的行有什么问题。 “错误 11 当前上下文中不存在名称‘行’”

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

最佳答案

文档中的示例中缺少一行:

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

如果切换到 Java View ,您可以看到 Java 版本包含这一行。

关于c# - 在谷歌电子表格中添加一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10518694/

相关文章:

java - 如何将 int(分钟)添加到 LocalDateTime.now()?

Python:__add__ 和 +, float 和整数的不同行为

c# - 如何将 BindingSource.DataSource 转换为自定义对象?

Python Pandas : fill a dataframe row by row

visual-c++ - MFC:如何更改 ListCtrl 各行的颜色/粗体?

mysql从多个表中选择计数

python - 从上一行/值 python 添加值

c# - C# 中 LINQ 查询的奇怪结果

c# - Windows Azure 平台上的演示应用程序?

c# - Async WebClient 不是真正的异步?