iOS将excel转plist
先把excel用Numbers打开,转换成CSV,然后新建一个工程,写下面的代码:
- (void)viewDidLoad { [super viewDidLoad]; [self writeToPlist];}- (void)writeToPlist { NSString *path = [[NSBundle mainBundle] pathForResource:@"高德地图API 城市编码表 2" ofType:@"csv"]; NSString *contents = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSLog(@"%@",contents); NSArray *contentsArray = [contents componentsSeparatedByString:@"\r\n"]; NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"shortcuts.plist"]; NSLog(@"路径:%@", docs); NSMutableArray *arr = [[NSMutableArray alloc] init]; NSInteger idx; for (idx = 0; idx < contentsArray.count; idx++) { NSString* currentContent = [contentsArray objectAtIndex:idx]; NSArray *timeDataArr = [currentContent componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]; NSMutableDictionary *dic = [[NSMutableDictionary alloc] init]; [dic setObject:[timeDataArr objectAtIndex:1] forKey:@"postCode"]; [dic setObject:[timeDataArr objectAtIndex:0] forKey:@"locationName"]; [dic setObject:[timeDataArr objectAtIndex:2] forKey:@"phoneCode"]; [arr addObject:dic]; } [arr writeToFile:docs atomically:YES];}