Jump to content

fputcsv & utf-8 characters displaying in excel


ahs10

Recommended Posts

so i am using fputcsv to create a csv file for to download.  all works well except that utf-8 characters won't display properly in excel.  however, the do display properly in numbers (apple's version of excel) and if i open the csv with text editor like bbedit, they display properly too.

 

here's the header information i have in my php file.  any ideas on how to get these characters (the ß character is the one i noticed) to display properly?

 

header('Content-type: application/csv; charset=utf-8; name="' . $fileName . '.csv"');

header('Content-Disposition: attachment; filename="' . $fileName . '.csv"');

 

Link to comment
Share on other sites

Not sure... perhaps when you import CSV to Excel, you can specify the encoding?

 

I'm pretty sure, that if two other programs show correct encoding, then the file itself is probably all right, and the issue lies somewhere in Excel.

Link to comment
Share on other sites

Ok. I just checked this with Excel 2007

 

Indeed, when you open a csv file with utf8 encoded characters, they come up as trash. It happens whether you double click the file, or open the fole from within Excel.

However, if you import the data from the text file (it's in 'Data' ribbon, third from the left in my installation), you can select the encoding, and then it displays properly.

Link to comment
Share on other sites

Mark: I suppose you can recommend some cool tool to do that. Am I right? ;)
Given that I've just implemented the 256th (a nice round number for those of us who think in binary) out of the 352 (including Cube and Database) functions in MS Excel, which is a significant milestone (to myself at the very least) - I'm of a mind to trumpet the fruits of my labours.  8)
Link to comment
Share on other sites

wow thanks guys... as long as i can pass it off as "not my fault" i'm good =) i figured it had to be something in excel since it opened up properly in bbedit.

 

the phpexcel project is amazing!  i might sign up to volunteer some code or time on that one.  i thought thinking like that died with that pear project that was almost there.... it was so close too.

 

thanks again, rock on!

Link to comment
Share on other sites

the phpexcel project is amazing!  i might sign up to volunteer some code or time on that one.  i thought thinking like that died with that pear project that was almost there.... it was so close too.
Glad to be of service... and PHPExcel could always use more active support. If you'd like to volunteer, hop over to the web site and drop us a line.

The core team is just three of us at the moment, and I'm about to go on a three month hiatus; but we have ambitious plans to introduce support for charts and pivot tables this year, not to mention improving the performance and reducing the memory overheads of the library.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.