Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create .CSV file with string and image in iPhone programmatically?

I want to create a csv file which contains both string and image. I am able to give the input as a strings separated by commas. Ex

NSArray  *paths  =    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); 
NSString *documentsDir   =    [paths objectAtIndex:0];
NSString *root   =    [documentsDir stringByAppendingPathComponent:@"products.csv"];
NSString *temp=@"jack,jil,jimmy,mike";
[temp writeToFile:root atomically:YES encoding:NSUTF8StringEncoding error:NULL];

In the above case it works fine. Now I need to add an image with the strings. I have the image as NSData. In this case how can I give the input to csv file.

I am also able to attach the image alone to a csv file as NSData. Ex

UIImage *img = [UIImage imageNamed:@"flower.png"];
NSData *dataObj = UIImageJPEGRepresentation(img, 1.0);
[dataObj writeToFile:root atomically:YES];

My expected output should contain both image and string if I open the csv file as Excel sheet.

like image 824
Warrior Avatar asked Nov 04 '22 20:11

Warrior


1 Answers

CSV file can contain only textual data. And, textual data of meaningful size. You'd better produce Excel XML with all the rows, text data inside it, and stored image inside.

like image 133
Nickolay Olshevsky Avatar answered Nov 12 '22 14:11

Nickolay Olshevsky