美文网首页
iOS 将excel转换成多个plist文件

iOS 将excel转换成多个plist文件

作者: JohnayXiao | 来源:发表于2018-02-08 14:13 被阅读29次

    只需将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];
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS 将excel转换成多个plist文件

          本文链接:https://www.haomeiwen.com/subject/hnrttftx.html