Googleスプレッドシートのセル値を更新したいのですが、残念ながらエラーが発生します。
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/)を使用しています。この問題の原因を知っていますか?
[編集]この問題は、gdatapythonクライアントでも報告されています。それがすぐに修正されることを願っています。http://code.google.com/p/gdata-python-client/issues/detail?id=692&sort=-opened&colspec=Opened%20Stars%20ID%20Type%20Status%20Priority%20Component%20Summary
ありがとうございました!
Googleがすべてのスプレッドシートを「新しい」形式に切り替えたように見える約1週間前に、この同じ問題が発生しました。
これは、GDataAPIを介して作成された新しいものにも当てはまります。どこでも400エラー。
GDataバリアントライブラリ(Python、Java、.Netなど)全体のレポートを掘り下げて、最終的にこの小さなナゲットを見つけました:https://stackoverflow.com/a/23438381/1685090
Etagプロパティを「*」に設定することが答えです:)
明確にするために、ワークシートでUpdate()を実行する場合はWorksheetEntry.Etagを設定し、SpreadsheetsService.Batch()を介してバッチ更新を行う場合はCellEntry.Etagも設定します。
これまでのところ、Googleの「新しい」スプレッドシートで問題なく動作しているようです。
このアプローチの1つの欠点は、同時/マージ操作がすべて無視されることです。基本的に、更新によってセル内の他の同時の以前の値が吹き飛ばされる必要があることをGoogleに伝えています。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加