- 分享
- 0
- 人气
- 0
- 主题
- 0
- 帖子
- 42
- UID
- 192466
- 积分
- 27
- 阅读权限
- 11
- 注册时间
- 2009-1-14
- 最后登录
- 2014-4-25
- 在线时间
- 181 小时

|
因使用的系統某些原因必須使用utf8環境,其產生的csv檔中 文字格式也是utf8的,但用excel開啟時會變成亂碼,用work開啟卻ok
不知是excel不認得utf8還是怎樣
將utf8的csv用記事本或是word重新開啟再另存新檔成ansi格式後,excel就能開了
但是將此種方法告訴用戶實在是有點不負責任,不知道有什麼方式能讓excel直接就能讀取utf8格式的csv呢?
code :
<?php
ob_start();
session_start();
function encoding_conv($var, $enc_out, $enc_in='utf-8') {
$var = htmlentities($var, ENT_QUOTES, $enc_in);
return html_entity_decode($var, ENT_QUOTES, $enc_out);
}
include_once ("include/include_file.php");
include_once ("../include/my_admin_security.php");
$table = 'tblappointment';
$file = 'consultation';
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j].", ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
$csv_output = encoding_conv($csv_output, 'Windows-1252', $enc_in);
print $csv_output;
exit;
?>
这个code是否有任何错误?因为这无法执行转换的功能
[ 本帖最后由 Crystal-Mist 于 2009-3-10 05:32 PM 编辑 ] |
|