Custom SQL Query To Excel In Yii1.0

Please read this tutorial before to follow this post. This tutorial will help you to create a excel sheet using custom sql query.

In Model Code

public function searchbydocumentdetails(){
    $query="SELECT * FROM TABLE_NAME";
        return new CSqlDataProvider($query,

In Controller Code

public function customsqltoexcel(){
    $document=new Document;
            'DocuemntName', 'CategoryName', 'DownloadCredits',
            'UploadCredits', 'Downloadimits', 'Count', 'Status'
        'Document Reports',
        array( 'creator' => 'Sourcecode'),
            'Excel2007'// This is the default value, so you can omit it. You can export to CSV, PDF or HTML too