From 7aef37ea08c6bdc013c14fee4713cc20b74137f1 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Mon, 5 Jul 2010 05:25:47 +0000 Subject: [PATCH] * fix the error of excel. --- module/file/control.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/module/file/control.php b/module/file/control.php index 34edcffece..881dc2ebaa 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -41,15 +41,30 @@ class file extends control /* 导出csv格式的文件。*/ public function export2csv($agent) { - $fileName = $this->post->fileName; + $fileName = $this->post->fileName; + $csvData = stripslashes($this->post->csvData); + + /* 如果是中文,尝试将编码转为gbk. */ + $clientLang = $this->app->getClientLang(); + if($clientLang == 'zh-cn' or $clientLang == 'zh-tw') + { + if(function_exists('mb_convert_encoding')) + { + $csvData = @mb_convert_encoding($csvData, 'gbk', 'utf-8'); + } + elseif(function_exists('iconv')) + { + $csvData = @iconv('utf-8', 'gbk', $csvData); + } + } + if(strpos($fileName, '.csv') === false) $fileName .= '.csv'; if($agent == 'ie') $fileName = urlencode($fileName); header('Content-type: application/csv'); header("Content-Disposition: attachment; filename=$fileName"); header("Pragma: no-cache"); header("Expires: 0"); - echo chr(0xEF) . chr(0xBB) . chr(0xBF); - echo stripslashes($this->post->csvData); + echo $csvData; die(); } }