phpexcel error

Hi All,

I am trying to generate a excel sheet and i am using phpexcel extention.

I have used the same example given phpexcel.

I have created a CHtml::button and on clicking this button a controller is called, here is the code


 public function actionExcelsheet()

        {

                $data = array(

                    1 => array ('Name', 'Surname'),

                            array('Schwarz', 'Oliver'),

                            array('Test', 'Peter')

                );

                Yii::import('application.extensions.phpexcel.JPhpExcel');

                $xls = new JPhpExcel('UTF-8', true, 'My Test Sheet');

                $xls->addArray($data);

                $xls->generateXML('my-test');

                die("hello");

                $this->render('excel');




        }



when i click on the button and trying to open the saved file it gives me an error

and error says general input/output error.

I am using LibreOffice spreadsheet 3.5.

Please help me out,its urgent.

Thanks in advance

You should get rid of the string in the call to die. This will be inserted into the file, not output to the browser.

hey Keith,

Thanks for the reply,but i have removed the die("hello"), it was copy and pasted by mistake.

Without the die also it is giving saame error.

What file size is the spreadsheet that you’re producing?

I’m not sure why you have a render call there, but I’ve not used this extension, so I might be missing something. If the generateXML() call outputs data to the browser, you should remove your render() call. Again, the render will output data to the file, which you don’t want.

If you need to render when a document isn’t generated, just call die after outputting the document, but don’t include a string argument.

Also, if the extension isn’t setting headers for you, you should really ensure that you’re sending download headers to the browser.

Thank you so much Keith,it solved my problem,it is working absolutely fine now.

I just copied the controllers code from some where didn’t notice to remove the render part.

Thanks a lot.

No probs. Do ensure the headers are being set correctly though, because different browsers will choke in different ways if you don’t.