以编程方式将Sqlite表数据导出到csv文件 - xcode iOS 5(用于ipad应用程序) [英] Exporting Sqlite table data to csv file programatically - xcode iOS 5 (for an ipad app)
问题描述
我正在开发一个简单的应用程序。我使用sqlite将数据保存到一个表(本地,在应用程序文档文件夹)。我想有问题地导出这个表数据在一个csv文件,并通过电子邮件发送给一个人。 以编程方式将SQLite数据导出到Excel中 - 我尝试过,但它不工作...可以任何人给一个示例应用程序下载?还是代码?
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?
目前,我在命令行中使用这些命令将数据库表转换为csv - .mode,.output out.csv,select * from table;
Currently, I am using these commands in command line to convert a db table to csv - .mode, .output out.csv, select * from table;
请帮助
推荐答案
这里我已经做了为表格数据生成csv 。
这里我做了简单的测试。但是你需要做的是以这样的方式生成2d数组,就像我在这个示例中做的一样生成NSArray。
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.
这里NSArray中的第一个组件是一行第二个组件用于表的第二行,同样...
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屋!