1.将excel内容拷贝到txt文件里,将txt文件的格式转换为纯文本格式
2.将该txt文件真正
的拖入工程, 不然会选取不到路径。
拖入的时候选取124。或者 add file。
3.代码存储。
NSURL *path = [[NSBundle mainBundle] URLForResource:@"city" withExtension:@"txt"];
NSString *contents = [[NSString alloc] initWithContentsOfURL:path encoding:NSUTF8StringEncoding error:nil];
NSArray *contentsArray = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"city.plist"] ;
NSLog(@"%@",docs);
// 定义数组
NSMutableArray *arr = [NSMutableArray array];
NSInteger idx;
for (idx = 0; idx < contentsArray.count; idx++) {
NSString* currentContent = [contentsArray objectAtIndex:idx];
// 字符串拆分 制表符
NSArray* timeDataArr = [currentContent componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\t"]];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:[timeDataArr objectAtIndex:0] forKey:@"ID"];
[dic setObject:[timeDataArr objectAtIndex:1] forKey:@"Code"];
[dic setObject:[timeDataArr objectAtIndex:2] forKey:@"Name"];
[dic setObject:[timeDataArr objectAtIndex:3] forKey:@"Initials"];
[dic setObject:[timeDataArr objectAtIndex:4] forKey:@"Pinyin"];
[dic setObject:[timeDataArr objectAtIndex:5] forKey:@"AreaCode"];
[arr addObject:dic];
}
// 数据写入plist文件
[arr writeToFile:docs atomically:YES];
4.参考文章
http://blog.csdn.net/wildfireli/article/details/7989840