2

ワークシートを開いて、ヘッダーからセルを読み取ることができます。Google スプレッドシートの最初の行はヘッダーで、Google スプレッドシートに「Name」、「my-val1」、「my-val2」、「my-val3」、「Other」を手動で追加しました。

関連する 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: 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}
4

1 に答える 1

5

このリンクによると、列名は小文字でコードにスペースを入れずに記述する必要があります。コードを変更した後に行が挿入されました。

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"
于 2012-07-10T13:55:38.637 に答える