5

Googleスプレッドシートからデータを取得する方法を最終的に理解した後、ファイルの最後に新しいエントリを追加する方法がわかりません.

これが私が達成したいことです: 私のアプリはいくつかの調査結果をGoogleスプレッドシートに送信する必要があります.ファイルは次のようになります:

ここに画像の説明を入力

次の調査結果をそのスプレッドシートに送信する必要があるとします。それらを送信して、最後のアンケート結果のすぐ下に表示されるようにするにはどうすればよいですか?

ありがとう

アップデート

私はずっと前に答え​​を見つけたので、このトピックに関する情報を見つけることができなかった私のような孤独なレンジャーのために質問を更新することにしました:)

この回答については、スプレッドシートのセル フィードにアクセスする方法を既に知っていることを前提としています。

セルフィードを取得した後に行う必要があることは次のとおりです。

  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