G. Tommy G. Tommy - 1 year ago 66
iOS Question

Write Google sheet cell

I try to find how modify or write a cell in a google sheet.
I success to read my sheet (on my drive) with quickstart guide (I had copied and pasted this code : https://developers.google.com/sheets/quickstart/ios#step_3_set_up_the_sample). I had just changed the url by :



But impossible to find a code to write on cells of my sheet... when i look : https://developers.google.com/sheets/guides/values#methods. I don't understand where i should put my new data to the cell.

Exemple : i have "New York" on the cell A1.
i want to change "New York" by "Tahiti".

Do you know how do that ?

i tried this but not working :

- (void)modifyListe {
NSString *baseUrl = @"https://sheets.googleapis.com/v4/spreadsheets/";
NSString *spreadsheetId = @"{MySpredsheet_ID}"; // choisir la bonne
NSString *range = @"/values/Feuil1!G1:G1?valueInputOption=Tahiti";

baseUrl = [baseUrl stringByAppendingString:spreadsheetId];
baseUrl = [baseUrl stringByAppendingString:range];

[self.service fetchObjectWithURL:[NSURL URLWithString:baseUrl]
objectClass:[GTLObject class]

SOLUTION : Look second post

Answer Source

I think found the solution (inspired by this post) :

NSString *baseUrl = @"https://sheets.googleapis.com/v4/spreadsheets/MyspreadsheetID/values/Donnees!G1:G1?valueInputOption=USER_ENTERED"; 
NSURL *theURL = [NSURL URLWithString:baseUrl];

    NSString *rangeKEY = @"range";
    NSString *dimensionKEY = @"majorDimension";
    NSMutableString *valuesKEY = [NSMutableString stringWithString:@"values"];

    NSString *therange = @"Donnees!G1:G1";
    NSString *themajorDimension = @"ROWS";
    NSMutableString *string_Value = [NSMutableString stringWithString:@"theValue"];

    NSMutableArray *ArrayOfString = [NSMutableArray array];
    NSMutableArray *arrayOfArray = [NSMutableArray array];

    [ArrayOfString addObject:string_Value];
    [arrayOfArray addObject:ArrayOfString];

    NSMutableDictionary *dicooo = [NSMutableDictionary dictionary];
    [dicooo setObject:arrayOfArray forKey:valuesKEY];
    [dicooo setObject:therange forKey:rangeKEY];
    [dicooo setObject:themajorDimension forKey:dimensionKEY];

    GTLObject *theobject ;
    theobject = [GTLObject objectWithJSON:dicooo];

    [self.service fetchObjectByUpdatingObject:theobject forURL:theURL delegate:self didFinishSelector:@selector(displayMajorsWithServiceTicketT:finishedWithObject:error:)];

When I launch I can see the modification on my sheet.