5

在最终弄清楚如何从谷歌电子表格中提取数据之后,我不明白如何将新条目添加到文件末尾。

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

在此处输入图像描述

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

谢谢

更新

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

对于这个答案,我假设您已经知道如何访问电子表格的单元格提要。

获得细胞饲料后,您需要执行以下操作:

  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];
    

而已!数据应上传到您的电子表格。

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

4

0 回答 0