Import Google Spreadsheet Cell data to Xcode UITex

2019-09-16 16:49发布

问题:

Is it possible to Get the data on a specific cell on Google spreadsheet and show it to iOS app Text fields. For Example, this Spreadsheet https://docs.google.com/a/ttttt.us/spreadsheet/ccc?key=0AkgWFqjLQz0TdEJSb3pYem9UcHo1Uzd0SU1QWm5xRFE#gid=0

I have an iOS app that has 2 Text fields. I want to show this Cells on each textfields I have. Everytime that the App opens, or maybe have some interval to refresh if the data in spreadsheet is changed. I hope someone will help me, thank you.!

EDIT:

i forgot to tell that i have a SpreadSheetApp delegate that can show a column of text to UIPickerView, when i click a text field that connected to that outlet, it shows the text and i can choose what i want.

NSString *theURL = @"https://docs.google.com/spreadsheet/pub?key=0AkgWFqjLQz0TdHdMQzBsc1lhaGFPZEFCYXBLWEt1Q0E&single=true&gid=1&output=txt";
    NSString *theFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:theURL] encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%@",theFile);
    NSArray *theCells = [theFile componentsSeparatedByString:@"\n"];

and this is the picker view code:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
      inComponent:(NSInteger)component
{
    switch (selectedTable) {
        case 0:
            self.txtLocation.text = [self.ar objectAtIndex:row];
            break;
        case 1:
            self.txtQuantity.text = [self.ar objectAtIndex:row];
            break;

now, how can i show the text without using picker view to select it, Instead it will automatically type in textfield when the app opens.

回答1:

This is a two step process. Firstly, you have to download the xls file on a regular basis to process the data. Per my knowledge, there's no way to essentially "listen" for changes on a particular cell in a file, especially since there's no way to authenticate you as the owner of that file. So that pretty much leaves you with just downloading the file on a regular basis and checking for changes (as you seem to expect). For that, you'll use the Google iOS API to sign in and download the file. See the example project on the linked website for that.

Secondly, you'll need to parse the xls file to get the value of the cell you're interested in and check for changes. See this answer on how to parse xls files.

Once you have the new value of the cell, you'll just compare it to the old one (ideally stored in a Core Data entry) and update the data entry and text field if needed.