sendFile('Test.xls') File name extension error

Hi All,

I want to generate an excel file (from an HTML table) like this:




Yii::app()->request->sendFile('Test.xls',

		$this->renderPartial('evaluation',array(

		'model'=>$model,

		//some other attributes

		'result'=>$result

		),

		true)

		);



Where ‘evaluation’ is an HTML table (and the data are the variables passed to the view).

I get an error:


"The file format differs from the format that the file name extension specifies..."

If I click yes, then the excel file is opened and the data are correct…

If I try to use .xlsx the file is opened without error but even the HTML tags are displayed!

How can I fix this error?

The sendFile method itself cannot convert html content (or any other) to xls file. You need to do additional work to make it happen like with the help of extension.

You can find extensions tagged with "Excel" here http://www.yiiframework.com/extensions/?tag=excel

Thank you Bizley for your answer.

The problem with those extensions is that all of them deal with CGridView data…

What I wanted is to export an HTML table including design…

The result is like this one:

6365

Excel.JPG

Which is "working fine" with the sendFile except that warning-error before opening the file…

Apparently Excel can read html files with basic table tags (didn’t know that before!). Anyway - this has nothing to do with sendFile method but… One thing you can try is to set third sendFile parameter which is $mimeType to one of the types recognized by Excel http://stackoverflow.com/questions/974079/setting-mime-type-for-excel-document although I’m not sure this will help with the error.