PDA

View Full Version : Import or Export a .numbers or CSV file?




BadWolf13
Sep 1, 2010, 09:53 PM
I've got this program that has an array of objects, which I'd like to be able to import or export to/from a common spreadsheet file type. So far I haven't had any luck finding a way to write the info to a simple CSV, XLS or Numbers file. Is there an API for this, or does anyone have any idea where to start? I really don't have a clue on this one.



kainjow
Sep 1, 2010, 11:32 PM
It's not a complicated format, just values separated by commas. See here:
http://en.wikipedia.org/wiki/Comma-separated_values

Simplest way would be to create the data with NSMutableString and then write it to file.

BadWolf13
Sep 2, 2010, 11:13 AM
No offense dude, but you don't need to tell me the painfully obvious, the merely obvious will do. Such as, how to write to a file in obj-c?

GorillaPaws
Sep 2, 2010, 11:21 AM
Edit: use the suggestion below

chown33
Sep 2, 2010, 11:21 AM
Use the NSString method writeToFile:atomically:encoding:error:

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/writeToFile:atomically:encoding:error:

Edit: Or use the suggestion above.

CMT
Sep 2, 2010, 02:30 PM
This tutorial may help:

http://www.macresearch.org/cocoa_for_scientists_part_xvii_representing_data_in_tables

BadWolf13
Sep 2, 2010, 09:34 PM
Thanks guys, those are both great ideas, and one great website.