iOS开发excel转plist文件

本文描述了一个使用Objective-C进行数据处理的过程,首先用Numbers打开Excel文件,去除多余行列并转为CSV格式,接着在工程中读取CSV文件内容,通过循环处理生成字典数组,并保存为plist文件。
摘要由CSDN通过智能技术生成

将excel用Numbers打开,删除表头等多余的行/列,转换成CSV,然后新建一个工程,使用模拟器运行起来,找到打印的路径:docs,前往文件夹,将该路径复制进去,即可找到转换后的plist文件

  1. - (void)viewDidLoad {
  2. [super viewDidLoad];
  3. [self writeToPlist];
  4. }
  5. - (void)writeToPlist {
  6. NSString *path = [[NSBundle mainBundle] pathForResource:@"高德地图API 城市编码表 2" ofType:@"csv"];
  7. NSString *contents = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  8. NSLog(@"%@",contents);
  9. NSArray *contentsArray = [contents componentsSeparatedByString:@"\r\n"];
  10. NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"shortcuts.plist"];
  11. NSLog(@"路径:%@", docs);
  12. NSMutableArray *arr = [[NSMutableArray alloc] init];
  13. for (NSInteger idx = 0 ; idx < contentsArray.count; idx++) {
  14. NSString* currentContent = [contentsArray objectAtIndex:idx];
  15. if(currentContent.length > 0) {
  16. NSArray *timeDataArr = [currentContent componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
  17. NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
  18. [dic setObject:[timeDataArr objectAtIndex:0] forKey:@"postCode"];
  19. [dic setObject:[timeDataArr objectAtIndex:1] forKey:@"locationName"];
  20. [dic setObject:[timeDataArr objectAtIndex:2] forKey:@"phoneCode"];
  21. [arr addObject:dic];
  22. }
  23. }
  24. [arr writeToFile:docs atomically:YES];
  25. }

部分操作图:

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值