加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Google Spreadsheets中的更新单元格返回错误“缺少资源版

发布时间:2020-12-16 02:01:03 所属栏目:百科 来源:网络整理
导读:我想更新Google Spreadsheets中的单元格值,但不幸的是收到错误: Google.GData.Client.GDataRequestException was unhandled HResult=-2146233088 Message=Execution of request failed: https://spreadsheets.google.com/feeds/cells/1nW8nxoS2l9pbj6dctreE
我想更新Google Spreadsheets中的单元格值,但不幸的是收到错误:

Google.GData.Client.GDataRequestException was unhandled
  HResult=-2146233088
  Message=Execution of request failed: https://spreadsheets.google.com/feeds/cells/1nW8nxoS2l9pbj6dctreEfKHNXmsfbbsCAvOd7TIj4Bo/od6/private/full/R1C1
  Source=Google.GData.Client
  ResponseString=Missing resource version ID
  StackTrace:
   at Google.GData.Client.GDataRequest.Execute()
   ...
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.WebException
   HResult=-2146233079
   Message=The remote server returned an error: (400) Bad Request.
   Source=System
   StackTrace:
        at System.Net.HttpWebRequest.GetResponse()
        at Google.GData.Client.GDataRequest.Execute()

我的代码非常简单,基于从https://developers.google.com/google-apps/spreadsheets/?csw=1#changing_contents_of_a_cell下载的示例:

SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

        // TODO: Authorize the service object for a specific user (see other sections)
        service.setUserCredentials("...","...");            

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

        foreach (SpreadsheetEntry spreadsheet in feed.Entries)
        {
            if (spreadsheet.Title.Text == "Test01")
            {
                // Get the first worksheet of the first spreadsheet.
                WorksheetFeed wsFeed = spreadsheet.Worksheets;
                WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];

                // Fetch the cell feed of the worksheet.
                CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
                cellQuery.MinimumRow = 1;
                cellQuery.MaximumRow = 10;
                cellQuery.MinimumColumn = cellQuery.MaximumColumn = 1;
                cellQuery.ReturnEmpty = ReturnEmptyCells.yes;
                CellFeed cellFeed = service.Query(cellQuery);

                // Iterate through each cell,updating its value if necessary.
                foreach (CellEntry cell in cellFeed.Entries)
                {
                    cell.InputValue = "Foooooo!";
                    cell.Update();
                }

            }
        }

在以下行引发错误:

cell.Update();

我使用Google.GData版本2.2.0.0(http://code.google.com/p/google-gdata/).
你知道什么可能导致这个问题吗?

[编辑]此问题也在gdata python客户端中报告过.希望很快得到修复.
http://code.google.com/p/gdata-python-client/issues/detail?id=692&sort=-opened&colspec=Opened%20Stars%20ID%20Type%20Status%20Priority%20Component%20Summary

谢谢!

解决方法

大约一周前,当Google似乎将所有电子表格翻转为“新”格式时,我们遇到了同样的问题.
这适用于通过GData api创建的新的.到处都是400个错误

我深入研究了GData变体库(Python,Java,.Net等)的报告,并最终找到了这个小块:
https://stackoverflow.com/a/23438381/1685090

将Etag属性设置为“*”就是答案:)

为了清楚起见,我们在工作表上运行Update()时设置WorksheetEntry.Etag,并且我们还在通过SpreadsheetsService.Batch()进行批量更新时设置CellEntry.Etag.

到目前为止,似乎与谷歌的“新”电子表格一起工作正常.

这种方法的一个优点是任何并发/合并操作都将被放弃 – 实质上,您告诉Google您的更新必须清除单元格中的任何其他并发先前值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读