在Google电子表格中添加一行 [英] Adding a row to a google spreadsheet

查看:338
本文介绍了在Google电子表格中添加一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向Google电子表格添加一行。他们提供了一个 https://developers.google.com/google-apps/spreadsheets的来源/#adding_a_list_row 但该来源不适合我,谁能告诉我请输入名称 row的行有什么问题。 错误11名称'row'在当前上下文中不存在

I'm trying to add a row to google spreadsheet. They give a source https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row bu this source is not working for me can anyone tell me please whats is wrong with lines witch include name "row". "Error 11 The name 'row' 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'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);
    }
}
}


推荐答案

文档的示例中缺少一行:

There's a line missing in the example in the 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" });

如果切换到Java视图,则可以看到Java版本包括这一行。

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

这篇关于在Google电子表格中添加一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆