iOS 将excel转换成多个plist文件

只需将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];
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,417评论 25 709
  • .bat脚本基本命令语法 目录 批处理的常见命令(未列举的命令还比较多,请查阅帮助信息) 1、REM 和 :: 2...
    庆庆庆庆庆阅读 12,561评论 1 19
  • 七绝.悼余老先生 文‖煮字疗伤 寒风冽冽铺天滚, 人间山河恸哭声。 偶闻先生仙逝去, 一生才气铸英名。
    落寞在凉州的烟雨里阅读 1,651评论 0 0
  • “白露到,竹竿摇。山核桃,下树了。”每临到白露节气,心中不由而然想到这句民谣。一转眼,又一个白露已来到,奔赴再远的...
    补拙莫如勤LV阅读 5,399评论 3 6
  • 人总会做出很多错误的选择,比如在该读书的时候选择了玩耍,在该面对的时候选择了回避,在该运动的时候选择了美食,来日方...
    莫哈max阅读 3,085评论 0 0