Problems viewing UTF-8 encoded CSV file with umlauts in QLPreviewController

In my app, I generate a UTF8-encoded CSV file with CHCSVWriter and display it using QLPreviewController. The file may have some special characters, such as umlauts (ü, ä), and I have checked the files and they are being generated properly. However when they are displayed with QLPreviewController, the characters are screwed up! I have checked my encodings throughout, and they are all UTF-8, so the code points are not being corrupted. Is there a problem with QLPreviewController? Any suggestions?

Here is the code I am using to create and display the CSV file:

NSString *path = @"my path";

CHCSVWriter *csvWriter = [[CHCSVWriter alloc] initWithCSVFile:path atomic:NO];
csvWriter.encoding = NSUTF8StringEncoding;
NSDictionary* w;
for (w in items) {
    [csvWriter writeField:[w valueForKey:@"a"]];
    [csvWriter writeField:[w valueForKey:@"b"]];
    [csvWriter writeLine];
}
[csvWriter closeFile];
[csvWriter release];

QLPreviewController *ql = [[QLPreviewController alloc] init];
[ql setDataSource:self];
[self presentModalViewController:ql animated:YES];
[ql release];

And here is what is being displayed:

Answers


I also have this problem when viewing utf-8 html files.

I solved it by setting <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> in the header.

UTF-16 or Latin1 worked fine without the encoding header, so if you ex. encode your file in UTF-16 it should work.


Ive have this problem also and I think it is a bug in the QLPReviewController. I filed a bug with Apple but haven't seen any resolution yet.


Got it..

try changing data encoding

csvWriter.encoding = NSUTF16BigEndianStringEncoding;

it worked for me..


Need Your Help

Automatically post form with onclick event

javascript forms events post onclick

There is a page that shows a button and needs user action to be able to do some event handlers.

How do I format a Date field of a .CSV file with multiple commas in a string field

linux csv sed awk cut

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: