如何使用 Google.GData.Client.AtomLinkCollection.FindService 方法获取 Google 电子表格中的工作表列表?

发布于 2024-09-29 03:41:11 字数 1383 浏览 2 评论 0 原文

我正在尝试编写与 Google 电子表格对话的代码。我们在我们这边进行了一系列处理,然后将数据传递给我们的客户到这个电子表格中,我想自动化它。这看起来应该很容易。

此页面上,Google 会显示“Given a SpreadsheetEntry you've已经检索到,您可以打印此电子表格中所有工作表的列表,如下所示:“

AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);

WorksheetQuery query = new WorksheetQuery(link.HRef.ToString());
WorksheetFeed feed = service.Query(query);

foreach (WorksheetEntry worksheet in feed.Entries)
{
    Console.WriteLine(worksheet.Title.Text);
}

在家里,我从以下内容开始:

Dim link As AtomLink = Entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, "")
Dim wsq As New WorksheetQuery(link.HRef.ToString)

当执行到第二行时,我发现“对象引用未设置为对象的实例。 ” FindService 方法没有返回任何内容。当我查看 GDataSpreadsheetsNameTable.WorksheetRel 时,它是“http://schemas.google.com/spreadsheets/2006#worksheetsfeed”的常量值,

我什至还没有真正理解它想要做什么。例如,什么是 Feed?工作表真的如我所认为的那样基于 Excel 命名法吗?那种东西。但我发现有几件事可能会导致我的问题:

  1. C# 方法调用“...FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);”我不确定那个空值。它需要一个字符串,所以我在 VB 中使用了“”,但我不确定这是否正确。
  2. schemas.google.com URI 似乎尚未上线。至少,如果我将其输入浏览器,我会发现找不到服务器。但我还是不知道它想做什么。

那么,有什么想法吗?有人有可以读取 Google 电子表格的 VB 代码并且有时间指导新手吗?我惊讶地发现网络上基本上没有有用的示例代码。

感谢您的阅读!

I'm trying to write code that talks to Google Spreadsheets. We do a bunch of processing on our end and then pass data out to our client into this spreadsheet and I want to automate it. This seems like it should be easy.

On this page, Google says "Given a SpreadsheetEntry you've already retrieved, you can print a list of all worksheets in this spreadsheet as follows:"

AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);

WorksheetQuery query = new WorksheetQuery(link.HRef.ToString());
WorksheetFeed feed = service.Query(query);

foreach (WorksheetEntry worksheet in feed.Entries)
{
    Console.WriteLine(worksheet.Title.Text);
}

Following along at home, I start with:

Dim link As AtomLink = Entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, "")
Dim wsq As New WorksheetQuery(link.HRef.ToString)

and when execution gets to that second line, I find that "Object reference not set to instance of an object." The FindService method is returning nothing. And when I look at GDataSpreadsheetsNameTable.WorksheetRel, it's a constant value of "http://schemas.google.com/spreadsheets/2006#worksheetsfeed"

I'm not really at the point where I even grok what it wants to be doing. E.g., what's a feed? Is a worksheet really what I think it is based on Excel nomenclature? That kind of stuff. But I see a couple of things that might be causing my issue:

  1. The C# method call "...FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);" I'm not sure about that null. It demands a string, so I used "" in my VB, but I'm not sure that's right.
  2. That schemas.google.com URI doesn't seem to be live. At least, if I punch it into a browser, I get server not found. But again, I don't exactly know what it's trying to do.

So, any thoughts? Anyone have VB code that reads Google Spreadsheets and time to instruct a newbie? I'm surprised to find that there's essentially no useful sample code floating around the net.

Thanks for reading!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少年亿悲伤 2024-10-06 03:41:11

所以,当然,在我发布这篇文章后,我在此处。手动迭代集合效果很好,即使这不是首选方法。我仍然渴望听到其他人提供的与此相关的信息,因此即使我可能已经克服了这一障碍,我仍会受到鼓励来提供帮助。

For Each Entry In mySprShFeed.Entries
    If Entry.Title.Text = "spreadsheetNameSought" Then
        For Each link As AtomLink In Entry.Links
            If link.Rel = GDataSpreadsheetsNameTable.WorksheetRel Then
                Dim wsf As WorksheetFeed = service.Query(New WorksheetQuery(link.HRef.ToString))
                For Each worksheet In wsf.Entries
                    Console.WriteLine(worksheet.Title.Text)
                Next

            End If
        Next
    End If
Next

So, of course, right after I posted this I found some inspiration over here. Manually iterating across the collections works just fine, even if it's not the preferred way to do this. I'm still keen to hear info from others related to this, so feel encouraged to help out even though I'm maybe over this one hurdle.

For Each Entry In mySprShFeed.Entries
    If Entry.Title.Text = "spreadsheetNameSought" Then
        For Each link As AtomLink In Entry.Links
            If link.Rel = GDataSpreadsheetsNameTable.WorksheetRel Then
                Dim wsf As WorksheetFeed = service.Query(New WorksheetQuery(link.HRef.ToString))
                For Each worksheet In wsf.Entries
                    Console.WriteLine(worksheet.Title.Text)
                Next

            End If
        Next
    End If
Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文