Reputation: 1
I want to write all the values present in an array to an excel sheet.Please suggest some way to do so.
Upvotes: 0
Views: 1216
Reputation: 1296
I will explain writing values out to a CSV file more detail. For example you have an array of Numbers: NSArray *array = @[@1,@2, @3,@1.01];
In this case your csv file will looks like this (usual text file with a number on each string):
1
2
3
1.01
So first step is writting a CSV file:
// composing a string with numbers from array separated by "\n" (line-endian symbol)
NSString *string = [array componentsJoinedByString:@"\n"];
// getting data from resulting string
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
// and writting data to disk
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"yourFileName.csv"];
[data writeToFile:appFile atomically:YES];
and the last step is to import the CSV into Excel (just open "yourFileName.csv" with an Excel application and click OK).
But if you want to save array directly in XLS file (without importing into CSV format) you, probably, have to read first answer to this question: iPhone SDK - Export data to XLS (not via CSV)
Upvotes: 0
Reputation: 8088
You have a few options:
Depends on what it is you are trying to accomplish
Frank
Upvotes: 1