将Sqlite表数据导出为csv文件 - xcode iOS 5(对于ipad应用程序) [英] Exporting Sqlite table data to csv file programatically - xcode iOS 5 (for an ipad app)
问题描述
目前,我在命令行中使用这些命令将数据库表转换为csv - .mode,.output out.csv,select * from table;
请帮助
这里我做了什么来生成csv表格数据。
这里我做了简单的测试。但是您需要做的是以这种方式生成2d数组,以生成NSArray,就像我在此示例中所做的那样。
这里NSArray中的第一个组件是一行表,第二个组件是第二行表,同样...
NSArray * array = [NSArray arrayWithObjects:@NAME ,NUMBER,@\\\
bhargavi1,12345,@\\\
Hiral,23456,@\Harish,34567,nil];
NSString * docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSString * filename = [NSString stringWithFormat:@test.csv];
NSString * filePathLib = [NSString stringWithFormat:@%@,[docDir stringByAppendingPathComponent:filename]];
[[array componentsJoinedByString:@,] writeToFile:filePathLib atomically:YES encoding:NSUTF8StringEncoding error:NULL];
请执行此操作。可能这可以帮助你。
我已经在我的项目中实现了这一点,它非常适合我
I am developing a simple app. I am using sqlite to save data into a table (locally, in app documents folder). I want to problematically export this table data in a csv file and email it to a person. Export SQLite data to Excel in iOS programmatically - I tried this, but its not working... Can anybody give an example application to download? Or the code?
Currently, I am using these commands in command line to convert a db table to csv - .mode, .output out.csv, select * from table;
Please help
Here what i have done to generate csv for tabular data. Here i have done it for simple testing. but what you need to do is to generate 2d array in such manner to produce NSArray like one i have done in this sample.
Here first component in NSArray is one row for table , second component is for second row of table and likewise...
NSArray *array = [NSArray arrayWithObjects:@"NAME,NUMBER",@"\nbhargavi1,12345",@"\nHiral,23456",@"\nHarish,34567", nil];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename=[NSString stringWithFormat:@"test.csv"];
NSString *filePathLib = [NSString stringWithFormat:@"%@",[docDir stringByAppendingPathComponent:filename]];
[[array componentsJoinedByString:@","] writeToFile:filePathLib atomically:YES encoding:NSUTF8StringEncoding error:NULL];
please implement this. May be this could help you out.
i have implement this in my project and it works for me very nicely
这篇关于将Sqlite表数据导出为csv文件 - xcode iOS 5(对于ipad应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!