如何以编程方式在iphone中创建csv文件? [重复]

问题描述 投票:2回答:2

这个问题在这里已有答案:

我想将数据库表转换为Iphone中的csv文件。我想在邮件中附加csv文件,因此可以在表格中以excel表格查看。我怎样才能实现它?

iphone csv
2个回答
3
投票

你应该看看Dave Delong制作的CHCSVParser。忽略这个名字,它也是一个作家。

它工作得很好;直到你想支持使用分号的德语(和其他)csv格式


1
投票

嘿我发现简单代码::

        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];
© www.soinside.com 2019 - 2024. All rights reserved.