Error generatinf xls file

Topics: Developer Forum
Jun 18, 2013 at 8:17 AM
I am using phpexcel to generate xls sheet.I tried the examples of the downloaded excel library and all seemed to be working fine.How ever when I integrated the library in my project where we use zend frame-work,I faced one issue.Though the xls file is generating but it contains lots of special character.My projects debug is off.This is my code :

require_once 'PHPExcel-Develop/Classes/PHPExcel.php';
    // Create new PHPExcel object
    $objPHPExcel = new PHPExcel();
    $blocksList = implode (", ", $blockNames);

    // Set document properties
    $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
    ->setLastModifiedBy("Maarten Balliauw")
    ->setTitle("Office 2007 XLSX Test Document")
    ->setSubject("Office 2007 XLSX Test Document")
    ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
    ->setKeywords("office 2007 openxml php")
    ->setCategory("Test result file");

    // Add some data
    ->setCellValue('A1', 'Hello')
    ->setCellValue('B1', 'world!')
    ->setCellValue('C1', 'Hello')
    ->setCellValue('D1', 'world!');

    // Rename worksheet

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet

    $objPHPExcel->getActiveSheet()->setCellValue("A2", "item1");
    $objPHPExcel->getActiveSheet()->setCellValue("A3", "item2");
    $objPHPExcel->getActiveSheet()->setCellValue("A4", "item3");
    $objPHPExcel->getActiveSheet()->setCellValue("B2", "Select Country");

    $objValidation = $objPHPExcel->getActiveSheet()->getCell("B2")->getDataValidation();
    $objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
    $objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
    $objValidation->setErrorTitle('Input error');
    $objValidation->setError('Value is not in list.');
    $objValidation->setPromptTitle('Pick from list');
    $objValidation->setPrompt('Please pick a value from the drop-down list.');


    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/');
    header('Content-Disposition: attachment;filename="01simple.xls"');
    header('Cache-Control: max-age=0');
    // If you're serving to IE 9, then the following may be needed
    header('Cache-Control: max-age=1');

    // If you're serving to IE over SSL, then the following may be needed
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header ('Pragma: public'); // HTTP/1.0

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
I am not able to attaching screen shot of the xls file .Pasted the contents of it..
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ş��Oh��+'��0�@Hh��
"   ᄏ"
"��*+������&ffffff�?'ffffff�?(�?)�?�""dXX333333�?333333�?U}$  }$  }$  �"
x��
WorksheetFeuilles
Thanks in Advance.
Jun 18, 2013 at 1:47 PM
It looks as though ZF is sending the file to the browser but with ZF sending its headers rather than yours.... you need to prevent ZF from sending its headers