Hi,

I've been using the sfPhpExcel in order to export data to Excel and
PDF.  The creation of the data object works fine and I've tested that
the data is indeed in the object.  However, when I go to download the
file the results are shown as symbols in the browser in the case of
Excel2007 and Excel5 formats or result in a blank page in the case of
PDF.

I upgraded the PhpExcel library that comes with sfPhpExcel with the
latest version to see whether that helped and to make use of some of
the new features.  However, that hasn't changed the export problem.

Below is the code for the action.

The spreadsheet is a multi-page workbook.

  public function executeExport(sfWebRequest $request)
  {
    /*
     * This aciton exports the model to a workbook or PDF.
     *
     */
    $model_id = $request->getParameter('model_id');
    $model = Doctrine::getTable('Model')->find($model_id);
    $type = $request->getParameter('type');
    $export = new ExportModel();
    $file_obj = $export->generateStaticSpreadsheet($model_id);

    $this->getResponse()->clearHttpHeaders();
    if ($type == 'Excel2007')
    {
      $this->getResponse()->setHttpHeader('Content-Type', 'application/
vnd.openxmlformats-officedocument.spreadsheetml.sheet');
      $file_name = $model->name.'_model.xlsx';
      $writer = new PHPExcel_Writer_Excel2007($file_obj);
    } elseif ($type == 'Excel2003') {
      $this->getResponse()->setHttpHeader('Content-Type', 'application/
vnd.ms-excel');
      $file_name = $model->name.'_model.xls';
      $writer = new PHPExcel_Writer_Excel5($file_obj);
    } elseif ($type == 'PDF') {
      $this->getResponse()->setHttpHeader('Content-Type', 'application/
pdf');
      $file_name = $model->name.'_model.pdf';
      $writer = new PHPExcel_Writer_PDF($file_obj);
      $writer->writeAllSheets();
    }
    $this->getResponse()->setHttpHeader('Content-
Disposition','attachment;filename='.$file_name);
    $this->getResponse()->setHttpHeader('Pragma', '');
    $this->getResponse()->setHttpHeader('Cache-Control', '');

    $error_reporting = error_reporting(0);
    $this->renderText($writer->save('php://output'));
    error_reporting($error_reporting);

    return sfView::NONE;
  }


>From looking through the forums and Google group, this code should
work so I'm at a loss as to why it isn't working.  I tried saving to
file and then loading the file but that didn't seem to work.

My guess to why it isn't working is that it has something to do with
the headers however, my research hasn't shown up any problems with
what is in the code.

Any help is greatly appreciated.

Regards,

Simon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to