excel表格中数据格式如图所示:
首先将excel表转换成csv文件,然后使用文本编辑器打开,如下图:
将内容复制到.txt文件中,然后在Xcode工程使用如下代码读取并写plist文件:
- (void)writeToPlist {
NSString *path = [[NSBundle mainBundle] pathForResource:@"shortcuts" ofType:@"txt"];
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:@"URL"];
[dic setObject:[timeDataArr objectAtIndex:0] forKey:@"name"];
[dic setObject:[timeDataArr objectAtIndex:2] forKey:@"type"];
[arr addObject:dic];
}
[arr writeToFile:docs atomically:YES];
}
去模拟器沙盒中对应路径找到plist文件
网友评论