如果 excel 的版本新一點,
對UTF8可以自動辨識的話,
基本上只要資料庫和 web 都用 UTF8 encode,
那不會有太大的問題,
遇到分隔用 \t , 換行用  \n
這是基本常識....

但要是遇到DB是存  utf8 , web 用 big5 ,
或是相反的話....
就要用 iconv 去轉編碼....(某些怪字會爛掉...)

更差的...客戶版本的 excel 怪怪或是太舊,
就要在 output excel加上更多的 編碼控制Q_Q
好一點的範例可以看看
http://bluecat.csie.net/2007/04/11/597/

有一段 sample code:

Sample

/*
General download setting
*/
//for IE & Opera
header("Content-Type: application/octetstream; name={$form_filename}; charset=UTF-8");
// for the rest
header("Content-Type: application/octet-stream; name={$form_filename}; charset=UTF-8");
header("Content-Disposition: attachment; filename={$form_filename};");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Pragma: no-cache”);;
header("Expires: 0");
/*
Force excel or browser use correct encoding
*/
echo "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; CHARSET=UTF-8\">";

 

 

萬一不幸遇到更糟的....怎麼樣都是亂碼 = =
請試著改用 table 的方式輸出 excel ,

除了可以解決編碼的問題外, 還能例用 table 做更多的表格位置控制...
一舉數得 :p

arrow
arrow
    全站熱搜

    阿貴貴 發表在 痞客邦 留言(0) 人氣()