美文网首页
如何将excel中数据转换成plist文件

如何将excel中数据转换成plist文件

作者: weirdyu | 来源:发表于2016-04-15 10:05 被阅读0次

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文件

相关文章

网友评论

      本文标题:如何将excel中数据转换成plist文件

      本文链接:https://www.haomeiwen.com/subject/ochnlttx.html