I want to convert a database table into a csv file in Iphone. I want to attach the csv file in mail, so it can be viewed in excel sheet in a table form. How can I achieve it?
2 Answers
you should have a look at CHCSVParser made by Dave Delong. Ignore the name, it's a writer, too.
It's working great; until you want to support the german (and others) csv format, which uses semicolons
2 Comments
Warrior
How to give input to the CHCSV Writter?
Matthias Bauch
Create a NSArray (for the rows) of NSArrays (for the columns) and then you can use the NSArray category method
writeToCSVFile:atomically: from NSArray+CHCSVAdditions.h. But there are other ways, please refer to the readme of CHCSVParserHey I Found Simple Code ::
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *root = [documentsDir stringByAppendingPathComponent:@"customers.csv"];
NSString *temp;
temp = [NSString stringWithFormat:@"%@", [arrCustomersName objectAtIndex:0]];
for (int i = 1; i < [arrCustomersName count]; i++) {
temp = [temp stringByAppendingFormat:@", %@", [arrCustomersName objectAtIndex:i]];
}
[temp writeToFile:root atomically:YES encoding:NSUTF8StringEncoding error:NULL];