我想创建一个包含字符串和图像的csv文件。我能够将输入作为以逗号分隔的字符串。实施例
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];
在上述情况下,它工作正常。现在我需要添加一个带有字符串的图像。我有像NSData的图像。在这种情况下,如何将输入提供给csv文件。
我也可以将图像作为NSData单独附加到csv文件中。实施例
UIImage *img = [UIImage imageNamed:@"flower.png"];
NSData *dataObj = UIImageJPEGRepresentation(img, 1.0);
[dataObj writeToFile:root atomically:YES];
如果我将csv文件作为Excel工作表打开,我的预期输出应包含图像和字符串。
答案 0 :(得分:2)
CSV文件只能包含文本数据。并且,有意义的大小的文本数据。 您最好生成包含所有行,文本数据和存储图像的Excel XML。