I have a big excel file and I want to be able to use this in my app and sort by name. I have 3 columns, name, height and weight.
Any advice would be so very greatly appreciated...I've been trying to do this for days and I don't know how to!
I have a big excel file and I want to be able to use this in my app and sort by name. I have 3 columns, name, height and weight.
Any advice would be so very greatly appreciated...I've been trying to do this for days and I don't know how to!
If you're not worried about parsing an actual CSV file in your iPhone app, but just about accessing the data, I would think about converting the CSV data into a .plist format. plist files (in text format) are very handy because they're human readable and you can suck the contents into an NSDictionary
or similar data structure at runtime with very little effort.
This is addressed in this question:
Convert Excel document (xls) to a plist
I've personally used the 'make a formula inside your spreadsheet to generate .plist file contents' approach successfully several times before. See Christopher Fairbairn's answer at the above link for more details.
A 3 column csv is a doddle to parse, assuming you've got control over it and there are no silly quoted commas or anything.
You can do it with the following untested pseudo-sorta-typed-on-my-phone-code:
NSString *fileContents = [NSString stringWithContentsOfFile:@"myFile.csv" encoding:_whatever_ error:nil];
NSMutableArray *parsedData = [NSMutableArray array];
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
for (NSString *line in lines)
{
NSArray *fields = [line componentsSeparatedByString:@","];
// add a dictionary or whatever to your array containing the relevant values from fields...
}