CVS文件导出

    /**
     * @param $filename 文件名
     */
    public function exportCxv($filename) {
        $filename = @iconv('UTF-8', 'GBK', $filename . '.csv');
        header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:attachment;filename=" . $filename);
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        $title = "标题栏,标题栏";
        echo @iconv('UTF-8', 'GBK//IGNORE', $title) . "\r\n";
    }

    /**
     * [csv 导出数据]
     * @param  [type] $data [数据]
     * @return [type]       [description]
     */
    public function csv($data) {
        if (!empty($data)) {
            foreach ($data as $key => $value) {
                $param = $value['param'];
                $date = date("Y-m-d H:i:s", $value['$date'] ? $value['$date'] : null);
                echo '"'.@mb_convert_encoding($param, 'GBK', 'UTF-8').'",';
                echo '"'.@mb_convert_encoding($date, 'GBK', 'UTF-8').'",';
                echo " \r\n";
            }
        }
    }

 

posted @ 2019-06-04 14:09  好胖的兔子  阅读(328)  评论(0编辑  收藏  举报