Add Header to make file download

    public function actionExport()


        $phpExcelPath = Yii::getPathOfAlias('application.vendors.PHPExcel.Classes');

        // 关闭YII的自动加载功能,改用手动加载,否则会出错,PHPExcel有自己的自动加载功能

        // YII框架对于组件的自动加载,要求类名与文件名一致;

        // 而PHPExcel类对应的文件名包含了上级目录名称,如:IOFactory类对应的文件名为PHPExcel_IOFactory.php


        include($phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php');

        // Create new PHPExcel object

        $objPHPExcel = new PHPExcel();  

        // Set properties        

        $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")

                                     ->setTitle("Office 2007 XLSX Test Document")

                                     ->setSubject("Office 2007 XLSX Test Document");

        // Add some data


        ->setCellValue('A1', 'Hello')

        ->setCellValue('B2', 'world!')

        ->setCellValue('C1', 'Hello')

        ->setCellValue('D2', 'world!');

        // Rename sheet


        // Set active sheet index to the first sheet, so Excel opens this as the first sheet


        // Redirect output to a client’s web browser (Excel5)

        header('Content-Type: application/');        

        header('Content-Disposition: attachment;filename="01simple.xls"');

        header('Cache-Control: max-age=0');        

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');









I want to save the .xls file, but I get some garbled, you can see the output in that picture, please tell me where is the problem, thanks.

You better post it in the forum of your language… :rolleyes:

I see, but in the Chinese forum there is no reply , and I’m very anxious.

I just want to get some help from the forum.

Can you see if this comment helps at all?