iOS 将excel转换成多个plist文件

只需将excel中的内容复制到一个txt文件,然后接下来你懂的。

效果如图

代码在此

- (void)createPlist {
    
    NSString *countriesPath = [[NSBundle mainBundle] pathForResource:@"countryInfo" ofType:@"txt"];
    NSString *countriesContent = [[NSString alloc] initWithContentsOfFile:countriesPath encoding:NSUTF8StringEncoding error:nil];
    NSArray *countriesArray = [countriesContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

    
//    NSString *plistPath = [NSHomeDirectory() stringByAppendingPathComponent:@"countryInfo.plist"];
    
    
    int i = 0;
    for (NSString *str in @[@"state",@"capital",@"birthday",@"song",@"language",@"currency",@"university",@"area",@"population",@"density",@"gdp",@"averageGdp",@"developmentIndex"]) {
        
        i++;
        NSString *plistPath = [NSString stringWithFormat:@"/Users/apple/Desktop/plistFiles/%@.plist", str];
        NSMutableArray *resultsArr = [[NSMutableArray alloc] init];
        
        for (NSInteger j = 0; j < countriesArray.count; j++){
            
            NSString *countriestr = [countriesArray objectAtIndex:j];
            
            NSArray *countryArr = [countriestr componentsSeparatedByString:@"\t"];
            
            [resultsArr addObject:@{@"country":[countryArr objectAtIndex:0],@"answer":[countryArr objectAtIndex:i]
                                    ,@"isRight":@"Y"}];
        }
        
        NSLog(@"%@:%@", str, plistPath);
        
        [resultsArr writeToFile:plistPath atomically:YES];
    }
}

你可能感兴趣的:(iOS 将excel转换成多个plist文件)