Recently I am working on a feature which exports the data presented on the web page to a csv file. That’s pretty easy, huh? The only trouble is the web site was built with Yii Framework…
Luckily, I found there’s already an light-weight extention called csvexport and you can find it here http://www.yiiframework.com/extension/csvexport
The usage example is pretty clear:
1 2 3 4 5 6 7 8 |
|
if you would like to download csv from browser instead of writing to a file, add this line:
1 2 |
|
Everything goes well so far. But when I open the new csv file with Excel 2008 (Mac), I found there’s a problem for human reading, because all data (more than 10 columns) are crowded in the first column, not separated by comma at all!!!
I checked the csv file carefully by opening it with textmate and found it’s rendering correctly, although not all data have the double quote enclosure. It does not effect the result.
The “csvexport” lib is using fputcsv to render csv.
1
|
|
The default delimiter is comma - “,” how about changing it to another one? Let’s try semicolon, Oops!!! It’s working great now.
1
|
|
Is it a Microsoft Office bug or php bug? Let me know your idea!