[symfony-users] Re: Output an excel file from an action
Thanks Kupo, everything works fine right now. thanks again for your help. Nicolas Binet --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
Nico, you have to remember that $this->renderText($text) does not return any data but rather sfView::NONE I think you should fix your code for clarity (although it works now) // Save Excel 5 file $error_reporting = error_reporting(0); $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); $xls_data = $objWriter->save(); error_reporting($error_reporting); return $this->renderText($xls_data); Kupo nico_bl1nd wrote: > thanks for your help, it works fine. > > finally my code looks like this : > > public function executeExport() > { > /** PHPExcel */ > include 'PHPExcel.php'; > > /** PHPExcel_Writer_Excel5 */ > include 'PHPExcel/Writer/Excel5.php'; > > // Create new PHPExcel object > $objPHPExcel = new PHPExcel(); > > // Set properties > $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); > $objPHPExcel->getProperties()->setLastModifiedBy("Maarten > Balliauw"); > $objPHPExcel->getProperties()->setTitle("Office 5 XLSX Test > Document"); > $objPHPExcel->getProperties()->setSubject("Office 5 XLSX Test > Document"); > $objPHPExcel->getProperties()->setDescription("Test document for > Office 5, generated using PHP classes."); > > // Add some data > $objPHPExcel->setActiveSheetIndex(0); > $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); > $objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!'); > $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello'); > $objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!'); > > // Rename sheet > $objPHPExcel->getActiveSheet()->setTitle('Simple'); > > $this->getResponse()->clearHttpHeaders(); > $this->getResponse()->setHttpHeader('Content-Type', 'application/ > vnd.ms-excel'); > $this->getResponse()->setHttpHeader('Content-Disposition:', > 'attachment; filename=export12.xls'); > > // Save Excel 5 file > $error_reporting = error_reporting(0); > $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); > $xls_data = $this->renderText($objWriter->save()); > error_reporting($error_reporting); > > return $xls_data; > } > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
thanks for your help, it works fine. finally my code looks like this : public function executeExport() { /** PHPExcel */ include 'PHPExcel.php'; /** PHPExcel_Writer_Excel5 */ include 'PHPExcel/Writer/Excel5.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw"); $objPHPExcel->getProperties()->setTitle("Office 5 XLSX Test Document"); $objPHPExcel->getProperties()->setSubject("Office 5 XLSX Test Document"); $objPHPExcel->getProperties()->setDescription("Test document for Office 5, generated using PHP classes."); // Add some data $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); $objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!'); $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello'); $objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!'); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Simple'); $this->getResponse()->clearHttpHeaders(); $this->getResponse()->setHttpHeader('Content-Type', 'application/ vnd.ms-excel'); $this->getResponse()->setHttpHeader('Content-Disposition:', 'attachment; filename=export12.xls'); // Save Excel 5 file $error_reporting = error_reporting(0); $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); $xls_data = $this->renderText($objWriter->save()); error_reporting($error_reporting); return $xls_data; } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
$this->getResponse()->setHttpHeader($name, $value, $replace = true) http://start.gotapi.com Sorry I did not verify before sending. for the errors you can use $error_reporting = error_reporting(0); ob_start() $xml_source = ... ob_clean(); error_reporting($error_reporting); Kupo nico_bl1nd wrote: > Hi Kupo, > > thanks for your message, > > So, after some tests: > > there is an error with $this->getResponse()->setHeader, it can't find > the setHeader method. > for testing I've set the headers manually : > header('Content-Type: ' . 'application/vnd.ms-excel'); > header('Content-Disposition: attachment; filename=export12.xls'); > > but the big problem is that the PHPExcel uses a lot of PHP4 dev style > (variable pass by reference, ...) > in dev the errors are reported and the output is bad, but in > production mode everything is ok. > > Now I need to find the setHeader method, and everything will be ok. > > Nicoas > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
Hi Kupo, thanks for your message, So, after some tests: there is an error with $this->getResponse()->setHeader, it can't find the setHeader method. for testing I've set the headers manually : header('Content-Type: ' . 'application/vnd.ms-excel'); header('Content-Disposition: attachment; filename=export12.xls'); but the big problem is that the PHPExcel uses a lot of PHP4 dev style (variable pass by reference, ...) in dev the errors are reported and the output is bad, but in production mode everything is ok. Now I need to find the setHeader method, and everything will be ok. Nicoas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
Nico, try the following in the end of your action: $this->getResponse()->clearHttpHeaders(); $this->getResponse()->setHeader('Content-Type', 'application/vnd.ms-excel'); $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=export12.xls'); // Save Excel 2007 file $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); return $this->renderText($objWriter->print()); } I am not sure about the function which prints the exel file so you will have to change that. the function renderText() return sfView:NONE and this is what you need. HEADERS_ONLY is really headers only and should be used for JSON stuff where the json code can be in the headers rather than in the content. You should use sfView::NONE if you do not want to use a template but still return content. Kupo nico_bl1nd wrote: > Hi Anakreon, > > I'm facing a similar problem. > I've made a simple export action and added the demo code from PHP > Excel, everything seems ok, the file is sent to my computer, but it's > completely empty. > Could you paste your PHPExcel code here ? > I don't know how to save the Excel. > > mine is the following : > > My action : > // Create new PHPExcel object > $objPHPExcel = new PHPExcel(); > > // Set properties > $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); > $objPHPExcel->getProperties()->setLastModifiedBy("Maarten > Balliauw"); > $objPHPExcel->getProperties()->setTitle("Office 5 XLSX Test > Document"); > $objPHPExcel->getProperties()->setSubject("Office 5 XLSX Test > Document"); > $objPHPExcel->getProperties()->setDescription("Test document for > Office 5, generated using PHP classes."); > > // Add some data > $objPHPExcel->setActiveSheetIndex(0); > $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); > $objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!'); > $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello'); > $objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!'); > > // Rename sheet > $objPHPExcel->getActiveSheet()->setTitle('Simple'); > > $this->getResponse()->clearHttpHeaders(); > header('Content-Type: ' . 'application/vnd.ms-excel'); > header('Content-Disposition: attachment; filename=export12.xls'); > > // Save Excel 2007 file > $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); > // $objWriter->save("php://output"); > > return sfView::HEADER_ONLY; > > > > My view.yml > > exportSuccess: > has_layout: false > > > thanks for your help > > Nicolas > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
In fact, it was a mistake in the code I've shown. When comment out this line, it doesn't work either. I've tried to write the file directly to disk, and it works $objWriter->save("/test.xls"); But sending the file for download doesn't work. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
I assume you need to call some method of $objWriter, like the line you commented out, for it to actually output the file. Right now your action has no output, you're sending nothing but the headers back. nico_bl1nd wrote: > Hi Anakreon, > > I'm facing a similar problem. > I've made a simple export action and added the demo code from PHP > Excel, everything seems ok, the file is sent to my computer, but it's > completely empty. > Could you paste your PHPExcel code here ? > I don't know how to save the Excel. > > mine is the following : > > My action : > // Create new PHPExcel object > $objPHPExcel = new PHPExcel(); > > // Set properties > $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); > $objPHPExcel->getProperties()->setLastModifiedBy("Maarten > Balliauw"); > $objPHPExcel->getProperties()->setTitle("Office 5 XLSX Test > Document"); > $objPHPExcel->getProperties()->setSubject("Office 5 XLSX Test > Document"); > $objPHPExcel->getProperties()->setDescription("Test document for > Office 5, generated using PHP classes."); > > // Add some data > $objPHPExcel->setActiveSheetIndex(0); > $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); > $objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!'); > $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello'); > $objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!'); > > // Rename sheet > $objPHPExcel->getActiveSheet()->setTitle('Simple'); > > $this->getResponse()->clearHttpHeaders(); > header('Content-Type: ' . 'application/vnd.ms-excel'); > header('Content-Disposition: attachment; filename=export12.xls'); > > // Save Excel 2007 file > $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); > // $objWriter->save("php://output"); > > return sfView::HEADER_ONLY; > > > > My view.yml > > exportSuccess: > has_layout: false > > > thanks for your help > > Nicolas > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
Hi Anakreon, I'm facing a similar problem. I've made a simple export action and added the demo code from PHP Excel, everything seems ok, the file is sent to my computer, but it's completely empty. Could you paste your PHPExcel code here ? I don't know how to save the Excel. mine is the following : My action : // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw"); $objPHPExcel->getProperties()->setTitle("Office 5 XLSX Test Document"); $objPHPExcel->getProperties()->setSubject("Office 5 XLSX Test Document"); $objPHPExcel->getProperties()->setDescription("Test document for Office 5, generated using PHP classes."); // Add some data $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); $objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!'); $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello'); $objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!'); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Simple'); $this->getResponse()->clearHttpHeaders(); header('Content-Type: ' . 'application/vnd.ms-excel'); header('Content-Disposition: attachment; filename=export12.xls'); // Save Excel 2007 file $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); // $objWriter->save("php://output"); return sfView::HEADER_ONLY; My view.yml exportSuccess: has_layout: false thanks for your help Nicolas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
On Sep 5, 2:59 pm, "Tristan Rivoallan" <[EMAIL PROTECTED]> wrote: > On 9/5/07, anakreon <[EMAIL PROTECTED]> wrote: > > > (output started at /home/anakreon/ekby_site/lib/PHPExcel/Shared/OLE/ > > OLE_Root.php:254) > > what do you see at this line in the file ? It ends the command which makes the first attempt to write content. > > it's probably just a whitespace problem : cleanup PHPExcel or make use > of output buffering. It doesn't seem to have any whitespace in what the command writes. I tried buffering too without success. There were two attempts. The first would set the content type and layout before the call to ob_start and the second after the call of ob_start. I call ob_end_flush() in the end of the action. The result is the same as before except that now it does not report the line number in the OLE_Root.php file. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: Output an excel file from an action
On 9/5/07, anakreon <[EMAIL PROTECTED]> wrote: > (output started at /home/anakreon/ekby_site/lib/PHPExcel/Shared/OLE/ > OLE_Root.php:254) what do you see at this line in the file ? it's probably just a whitespace problem : cleanup PHPExcel or make use of output buffering. > Also, the page ends with content type text/html. that's related to previous problem : headers are not sent, so your content-type is not taken into account. ++ tristan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---