在iOS中使用GData API在Google电子表格中插入新单元格

时间:2013-06-12 19:13:56

标签: iphone ios objective-c spreadsheet gdata

在最终弄清楚如何从谷歌电子表格中提取数据之后,我无法理解如何在文件末尾添加新条目。

这是我想要实现的目标: 我的应用程序应该将一些调查结果发送到谷歌电子表格,这是文件的外观:

enter image description here

我们假设我需要将下一个调查结果发送到该电子表格。如何发送它们并确保它们出现在最后一次调查结果之下?

由于

更新

我很久以前就找到了一个答案,所以决定更新像我这样找不到任何关于此主题的游侠的问题:)

对于这个答案,我假设您已经知道如何进入电子表格的单元格Feed。

以下是获取细胞后需要执行的操作:

  1. 首先,我们需要查找最后一行编号,以便稍后写入其下的行。

    NSArray * entries = [cellsFeed entries]; // we pull out all the entries from the feed
    GDataEntrySpreadsheetCell * lastCell = [entries lastObject]; // then we take just the last one
    NSString * title = [[lastCell title] stringValue]; // then we need it's title. The cells title is a combination of the column letter and row number (ex: A20 or B5)
    NSString * lastRow = [[title componentsSeparatedByCharactersInSet:
                           [[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
                          componentsJoinedByString:@""]; // then we remove the letters and we're left only with the row number
    
  2. 我们现在可以将一些数据发送到最后一行的行,如下所示:

     // create a cell object and give it the row number (in our case it's the row under lastRow, so we add + 1), column number (yes, here you should provide a number and not a letter) and the string that you want to appear in the cell
        GDataSpreadsheetCell * cell = [GDataSpreadsheetCell cellWithRow:[lastRow intValue] + 1 column:1 inputString:@"some value" numericValue:nil resultString:nil];
    
       // create a cellEntry object that will contain the cell
        GDataEntrySpreadsheetCell * cellEntry = [GDataEntrySpreadsheetCell spreadsheetCellEntryWithCell:cell];
    
       // upload the cellEntry to your spreadsheet
       [_srv fetchEntryByInsertingEntry:cellEntry
                      forFeedURL: [[workSheet cellsLink] URL] // make sure that you save the workSheet feed in an instance variable so that you'll be able to reach it in another method. If you pulled data from the spreadsheet that you must already know how to get the worksheet feed
                        delegate:self
               didFinishSelector:nil];
    
  3. 就是这样!数据应上传到您的电子表格。

    如果您有任何问题,请告诉我,我知道文档有点稀缺。

0 个答案:

没有答案