views:

38

answers:

1

Hi,

I need to create and export an excel file in my iPhone app. Unfortunately, excel won't read it if the line encoding is LF (the unix default when I write the file) instead of CRLF (the Windows standard)...Is there any way to write a file using CRLF line breaks?

I can tell this is the issue as if I open the file in TextWrangler after outputting it, then change the line breaks to CRLF, excel opens it fine.

Thanks,

Toby

+2  A: 

If you're using printf or fprintf in C you typically terminate lines like this:

printf( "this is a line of text.\n" );

The \n outputs a linefeed. You can output a carriage return with \r, so to get a CRLF, you just:

printf( "this is a CRLF terminated line.\r\n" );
progrmr
Sorry, I guess I should have included more detail, though hopefully the solution's still as simple. I'm reading the excel file into an NSString, replacing the default values, then outputting it. The source file uses CRLF line breaks, but when I output it using [NSString writeToFile...] it seems to replace these with LF. I've tried using [NSString stringByReplacingOccurrencesOfString:@"\n" withString:@"\r\n"] but it doesn't work.
Toby