开发者

How to create csv file in iphone programmatically? [duplicate]

开发者 https://www.devze.com 2023-02-14 13:40 出处:网络
This question already has answers here: How to export data to a csv file with iOS? (4 answers) Closed 3 years ago.
This question already has answers here: How to export data to a csv file with iOS? (4 answers) Closed 3 years ago.

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号