How to create csv file in iphone programmatically? [duplicate]
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?
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
Hey 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];
精彩评论