使用 gdata-objectivec-client 批量插入电子表格单元格不起作用
我正在尝试使用 GData Objective-C 客户端将一批单元格添加到 Google 电子表格中,如下所述:http://code.google.com/p/gdata-objectivec-client/wiki/GDataObjCIntroduction#Batch_requests。
这是感兴趣的代码:
GDataFeedSpreadsheetCell *batchFeed = [GDataFeedSpreadsheetCell spreadsheetCellFeed];
NSURL *batchUrl = [[batchFeed batchLink] URL];
NSMutableArray *cells = [NSMutableArray array];
GDataSpreadsheetCell *cell = [GDataSpreadsheetCell cellWithRow:1 column:1 inputString:@"test" numericValue:nil resultString:nil];
GDataEntrySpreadsheetCell *cellEntry = [GDataEntrySpreadsheetCell spreadsheetCellEntryWithCell:cell];
[cells addObject:cellEntry];
[batchFeed setEntries:cells];
GDataBatchOperation *op;
op = [GDataBatchOperation batchOperationWithType:kGDataBatchOperationInsert];
[batchFeed setBatchOperation:op];
[service fetchFeedWithBatchFeed:batchFeed forBatchFeedURL:batchUrl completionHandler:nil];
它不起作用。显然, fetchFeedWithBatchFeed 没有引用我的 GDataWorksheetEntry 对象 - 因此它不起作用并不令我感到惊讶。
我遗漏了什么?
提前致谢。
I am trying to add a batch of cells to a Google Spreadsheet using the GData Objective-C Client as described here: http://code.google.com/p/gdata-objectivec-client/wiki/GDataObjCIntroduction#Batch_requests.
Here is the code of interest:
GDataFeedSpreadsheetCell *batchFeed = [GDataFeedSpreadsheetCell spreadsheetCellFeed];
NSURL *batchUrl = [[batchFeed batchLink] URL];
NSMutableArray *cells = [NSMutableArray array];
GDataSpreadsheetCell *cell = [GDataSpreadsheetCell cellWithRow:1 column:1 inputString:@"test" numericValue:nil resultString:nil];
GDataEntrySpreadsheetCell *cellEntry = [GDataEntrySpreadsheetCell spreadsheetCellEntryWithCell:cell];
[cells addObject:cellEntry];
[batchFeed setEntries:cells];
GDataBatchOperation *op;
op = [GDataBatchOperation batchOperationWithType:kGDataBatchOperationInsert];
[batchFeed setBatchOperation:op];
[service fetchFeedWithBatchFeed:batchFeed forBatchFeedURL:batchUrl completionHandler:nil];
It doesn't work. Clearly, the fetchFeedWithBatchFeed has no reference to my GDataWorksheetEntry object -- so it doesn't surprise me that it isn't working.
What am I leaving out?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是最终的答案。
您必须在批量更新之前执行查询以获取要更新的条目。回想起来,这听起来很明显。当然,确实会产生很多嵌套块。
And here is the final answer.
You must perform a query before the batch update to get the entries you are going to update. Sounds obvious in retrospect. Sure does make for a lot of nested blocks though.
我解决了这个问题并暴露了一个新问题。
首先,解决方案。一旦您有了 GDataWorksheetEntry,此代码将执行批处理操作 - 在本例中为插入:
不幸的是,当您访问生成的批处理提要(在日志记录语句中完成)时,您将看到以下内容
:)
所以现在我需要弄清楚如何解决 Google 缺乏对批量插入支持的问题。
请注意,如果您更改更新操作,您会得到以下结果
:)
缺少的条目 ID 是因为我创建单元格时没有引用现有单元格 - 因此我将专注于尝试提供该引用并提供批量更新调用,而不是批量插入调用。
I solved this problem and exposed a new issue.
First, the solution. Once you have a GDataWorksheetEntry, this code will perform a batch operation -- in this case an insert:
Unfortunately, when you access the resulting batch feed (done in the logging statement) you will see this:
)
So now I need to figure out how to hack around Google's lack of support for batch insertion.
Note that if you change the operation to update you get this:
)
The missing entry id is because I created the cell without referencing an existing cell -- so I will focus on trying to provide that reference and providing a batch update call instead of a batch insert call.