zoukankan      html  css  js  c++  java
  • iOS将excel转plist

    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:@"
    "];
        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];
    }
  • 相关阅读:
    [CQOI2011]放棋子
    [JSOI2015]染色问题
    [ZJOI2016]小星星
    [NOI2018]你的名字
    bzoj2393 Cirno的完美算数教室
    [CQOI2012]局部极小值
    CF768F Barrels and boxes
    bzoj4402 Claris的剑
    烽火SATA SSD DSS200-B
    添加防火墙规则
  • 原文地址:https://www.cnblogs.com/tufei7/p/8504079.html
Copyright © 2011-2022 走看看