Saving CSV in cocoa

Posted by happyCoding25 on Stack Overflow See other posts from Stack Overflow or by happyCoding25
Published on 2010-04-18T19:56:59Z Indexed on 2010/04/18 20:03 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

Hello,

I need to make a cvs file in cocoa. To see how to set it up I created one in Numbers and opened it with text edit it looked like this:

Results,,,,,,,,,,,,
,,,,,,,,,,,,
A,10,,,,,,,,,,,
B,10,,,,,,,,,,,
C,10,,,,,,,,,,,
D,10,,,,,,,,,,,
E,10,,,,,,,,,,,

So to replicate this in cocoa I used:

NSString *CVSData = [NSString stringWithFormat:@"Results\n,,,,,,,,,,,,\nA,%@,,,,,,,,,,,\nB,%@,,,,,,,,,,,\nC,%@,,,,,,,,,,,\nD,%@,,,,,,,,,,,\nE,%@,,,,,,,,,,,",[dataA stringValue], [dataB stringValue], [dataC stringValue], [dataD stringValue], [dataE stringValue]]; 

Then

[CVSData writeToFile:[savePanel filename] atomically:YES];

But when I try to open the saved file with Numbers I get the error “Untitled.cvs” could not be handled because Numbers cannot open files in the “Numbers Document” format. Could this be something with the way cocoa is encoding the file?

Thanks for any help

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about encoding