iOS 将excel转换成多个plist文件

2018-02-08  本文已影响29人  JohnayXiao

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

效果如图

WX20180208-140946@2x.png WX20180208-141049@2x.png WX20180208-141131@2x.png

代码在此

- (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];
    }
}
上一篇下一篇

猜你喜欢

热点阅读