I am making a simple CSV file in my application, and I use characters such as ‘æøå’. When I open the file on my Mac with BBEdit it opens the file correctly, but if I import the file in Excel (MS Office 2011) with Unicode UTF-8 it does not show the characters correctly. How do I fix this?
Some of the code:
NSString *tmpPath = NSTemporaryDirectory();
NSString *fullPath = [tmpPath stringByAppendingPathComponent:@"log_export.csv"];
[csvComplete writeToFile:fullPath atomically:YES encoding:NSUTF8StringEncoding error:NULL];
I am mailing the csv.
[mailController addAttachmentData:data mimeType:@"text/csv" fileName:@"sertifikat-loggbok.csv"];
CSV is a text format that does not specify the character encoding. Different applications assume different encodings.
My experience is that Microsoft Excel assumes it’s in the default encoding which happens to be CP1250 (similar to ISO 8859-1 / Latin 1 encoding) on my machine. Maybe it always assumes CP1250.
So try to switch from UTF-8 to CP1250. But I cannot guarantee it’ll always work because there simply is no encoding specified for CSV.