无法将行添加到Google电子表格 [英] Cannot add a row to Google Spreadsheet
问题描述
我可以打开工作表并从标题中读取单元格。 Google Spreadsheet中的第一行是标题,我在Google电子表格中手动添加了名称,my-val1,my-val2,my-val3,其他。 b
$ b
以下是相关的Google文档:
https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row
我我试图向工作表中添加一行,但得到相当一般的错误远程服务器返回错误:(400)错误的请求。任何想法我做错了什么?
以下是代码:
AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel,null);
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = myService.Query(listQuery);
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom(){LocalName =Name,Value =Joe});
row.Elements.Add(new ListEntry.Custom(){LocalName =my-val1,Value =Smith});
row.Elements.Add(new ListEntry.Custom(){LocalName =my-val2,Value =26});
row.Elements.Add(new ListEntry.Custom(){LocalName =my-val3,Value =176});
row.Elements.Add(new ListEntry.Custom(){LocalName =Other,Value =176});
myService.Insert(listFeed,row);
以下是错误讯息:
Google.GData.Client.GDataRequestException:执行请求失败:https://spreadsheets.google.com/feeds/list/tlb-JYE8eZbWTRPCoqugCqw/od6/private/full ---> System.Net.WebException:远程服务器返回错误:(400)错误的请求。
at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.GDataRequest.Execute()
---内部异常堆栈跟踪结束---
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
在Google.GData.Client.Service.Insert(Uri feedUri,AtomEntry newEntry,AsyncSendData数据)
在Google.GData.Client.Service.EntrySend(Uri feedUri,AtomBase baseEntry,GDataRequestType类型,AsyncSendData数据)
在Google.GData.Client.Service.Insert [TEntry](Uri feedUri,TEntry条目)
位于Google.GData.Client.Service.Google.GData.Client.IService.Insert(AtomFeed提要,AtomEntry条目)
at Google.GData.Client.Service.Insert [TEntry](AtomFeed feed,TEntry entry)
at DesktopControl.GoogleSpreadsheet.addRow()in C:\Users\mark\Documents\ Visual Studio 2008 \Projects\DSCON\DSCON\\ GoogleSpreadsheet.cs:第248行}
此链接,列名必须在小写字母和代码中没有空格。更改代码后插入行:
row.Elements.Add(new ListEntry.Custom(){LocalName =name ,Value =Joe}); //Name改为name
row.Elements.Add(new ListEntry.Custom(){LocalName =my-val1,Value =Smith});
row.Elements.Add(new ListEntry.Custom(){LocalName =my-val2,Value =26});
row.Elements.Add(new ListEntry.Custom(){LocalName =my-val3,Value =176});
row.Elements.Add(new ListEntry.Custom(){LocalName =other,Value =176}); //其他更改为其他
I am able to open the worksheet and read cells from the header. The first line in a Google Spreadsheet is the header and I have manually added "Name", "my-val1", "my-val2", "my-val3", "Other" in the Google spreadsheet.
Here is the relevant Google documentation:
https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row
I am trying to add a row to the worksheet, but get the rather generic error "The remote server returned an error: (400) Bad Request." Any idea of what I'm doing wrong?
Here is the code:
AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = myService.Query(listQuery);
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "Name", Value = "Joe" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "my-val1", Value = "Smith" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "my-val2", Value = "26" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "my-val3", Value = "176" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "Other", Value = "176" });
myService.Insert(listFeed, row);
Here is the error message:
Google.GData.Client.GDataRequestException: Execution of request failed: https://spreadsheets.google.com/feeds/list/tlb-JYE8eZbWTRPCoqugCqw/od6/private/full ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.GDataRequest.Execute()
--- End of inner exception stack trace ---
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data)
at Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry, AsyncSendData data)
at Google.GData.Client.Service.Insert[TEntry](Uri feedUri, TEntry entry)
at Google.GData.Client.Service.Google.GData.Client.IService.Insert(AtomFeed feed, AtomEntry entry)
at Google.GData.Client.Service.Insert[TEntry](AtomFeed feed, TEntry entry)
at DesktopControl.GoogleSpreadsheet.addRow() in C:\Users\mark\Documents\Visual Studio 2008\Projects\DSCON\DSCON\GoogleSpreadsheet.cs:line 248}
Alright, according to this link, the column names must be stated in small letters and without spaces in the code. The row was inserted after changing the code:
row.Elements.Add(new ListEntry.Custom() { LocalName = "name", Value = "Joe" }); // "Name" changed to "name"
row.Elements.Add(new ListEntry.Custom() { LocalName = "my-val1", Value = "Smith" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "my-val2", Value = "26" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "my-val3", Value = "176" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "other", Value = "176" }); // "Other" changed to "other"
这篇关于无法将行添加到Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!