1.将Excel的文件另存为.csv文件
2.使用文本编辑打开.csv
3.新建一个文本编辑的文档,使用制作纯文本的模式
4.将.csv的内容复制至新建的文档中
5.注意最后一行是否存在空白行,如果存在,需要删除
6.如果Excel中存在这些不必要的导入内容,可以直接删除。
8.导入项目
NSString *path = [[NSBundle mainBundle] pathForResource:@"未命名" ofType:@"txt"];
NSString *contents = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *contentsArray = [contents componentsSeparatedByString:@"\n"];
NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"content.plist"];
NSLog(@"%@",docs);//这里打印的路径为生成的plist的路径地址
NSMutableArray *arr = [[NSMutableArray alloc] init];
for (int i = 0; i < contentsArray.count; i++) {
NSString *currentContent = [contentsArray objectAtIndex:i];
NSArray *timeDataArr = [currentContent componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:[timeDataArr objectAtIndex:1] forKey:@"code"];
[dic setObject:[timeDataArr objectAtIndex:2] forKey:@"nationality"];
[arr addObject:dic];
}
[arr writeToFile:docs atomically:YES];
生成的内容如下: