Mac下使用数据库将Excel数据转换存入.plist

记录于2013/10/26
 
基本步骤:
1、将Excel表格另存为.csv格式
2、用类似TextWrangler工具将.csv文件转成UTF-8格式
3、使用火狐插件SQLite Manager新建数据库,导入.csv文件(注意命名,最好是全英文)
4、代码中读取数据库文件(可使用类似FMDB第三方库),代码简单如下: 
 NSString*path = [[NSBundlemainBundle]pathForResource:@"DB.sqlite"ofType:nil];
   FMDatabase*db = [FMDatabasedatabaseWithPath:path];
   
   if(![dbopen]) {
       NSLog(@"数据库打开失败");
       
       return;
    }else{
       NSLog(@"打开成功");
    }

FMResultSet*results = [dbexecuteQuery:@"SELECT * FROM BatteryUTF8"];

    while ([results next]) {
          NSLog(@"%@     %@   %@  %@  %@  %@", [results objectForColumnIndex:0],[results objectForColumnIndex:1],[results objectForColumnIndex:2],[results objectForColumnIndex:3],[results objectForColumnIndex:4],[results objectForColumnIndex:5]);
}

5、代码写入plist文件,然后从沙盒中拷贝出该文件

NSArray*doc =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
   NSString*docPath = [ docobjectAtIndex:0];
   
    [ arraywriteToFile:[docPathstringByAppendingPathComponent:@"Battery.plist"]atomically:YES];
    NSLog(@"pathPlist:%@",docPath);

 

 

 

 
posted @ 2019-01-03 18:03  小、  阅读(457)  评论(0编辑  收藏  举报