将Excel文件转为plist文件

1.mac自带launchpad——>其他 ——》 文本编辑 ——》 打开 ——》 commod+shift+T(转换成txt格式输入框),将excel文本粘贴进txt文本框——》保存

2.将xx.txt文件拖入工程,按照以下代码转换

NSString *schoolsPath = [[NSBundle mainBundle] pathForResource:@"provinceCity" ofType:@"txt"];

    NSString *schoolsContent = [[NSString alloc] initWithContentsOfFile:schoolsPath encoding:NSUTF8StringEncoding error:nil];

    NSArray *schoolsArray = [schoolsContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

    

    NSString *plistPath = [NSHomeDirectory() stringByAppendingPathComponent:@"province.plist"];

    NSMutableArray *resultsArr = [[NSMutableArray alloc] initWithCapacity:0];

    for (NSInteger j = 37; j < 347; j++){

        NSString *schoolStr = [schoolsArray objectAtIndex:j];

        NSArray *schoolArr = [schoolStr componentsSeparatedByString:@"\t"];

        [resultsArr addObject:@{@"schoolName":[schoolArr objectAtIndex:2]}];

    }

//    NSLog(@"%@",resultsArr);

     NSLog(@"%@",plistPath);

    [resultsArr writeToFile:plistPath atomically:YES];

 

转载于:https://www.cnblogs.com/zbuser/p/5398225.html

你可能感兴趣的:(将Excel文件转为plist文件)