Error generatinf xls file

Topics: Developer Forum
Jun 18, 2013 at 7:17 AM
Hi,
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();
    $blockNames=array("test","google");
    $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
    $objPHPExcel->setActiveSheetIndex(0)
    ->setCellValue('A1', 'Hello')
    ->setCellValue('B1', 'world!')
    ->setCellValue('C1', 'Hello')
    ->setCellValue('D1', 'world!');



    // Rename worksheet
    $objPHPExcel->getActiveSheet()->setTitle('Simple');


    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    $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->setAllowBlank(false);
    $objValidation->setShowInputMessage(true);
    $objValidation->setShowErrorMessage(true);
    $objValidation->setShowDropDown(true);
    $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.');

    $objValidation->setFormula1('"test,test2,test3,test,4th,"');

    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/vnd.ms-excel');
    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');
    $objWriter->save('php://output');
    exit;
I am not able to attaching screen shot of the xls file .Pasted the contents of it..
��ࡱ�

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ş��Oh��+'��0�@Hh��
���Untitled
��B�=�%r8X"1��Calibri��
Block
House
"   ᄏ"
"��*+������&ffffff�?'ffffff�?(�?)�?�""dXX333333�?333333�?U}$  }$  }$  �"
�
�
>ᄊ@gg?????
����՜.��+,�0�HPX`hp
x��
WorksheetFeuilles
Thanks in Advance.
Coordinator
Jun 18, 2013 at 12: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