problem with PHPExcel

Oct 31, 2011 at 2:09 PM

Hello!
I use PHPExcel for the first time. When I launch the application, all the php code is displayed in the browser so the excel document does not appear. Can anyone help me please?
here is the code:

<?
//------------------------------------------------------------------.
// Variable de session pour informer sur le statut de la génération |
//------------------------------------------------------------------'
@session_start(); 
$_SESSION['generationStatut'] = "progress";

//----------------------------------------------------------------------------.
// Termine la session courante, après avoir stocké les données, autrement dit |
// on force le stockage de la variable de session pour qu’elle puisse être    |
// utilisé dans le script generationStatus.php lancé en AJAX retardé récursif |
//----------------------------------------------------------------------------'
session_write_close();
 
//------------------------------.
// Création de l'objet PHPExcel |
//------------------------------'
include_once("../etat_financier/class_etat/classXLS/PHPExcel.php");
$dateGeneration = date('d/m/Y \à H:i:s');
$objPHPExcel = new PHPExcel();
    $objPHPExcel->setActiveSheetIndex(0);
    $objPHPExcel->getDefaultStyle()->getFont()->setName('Calibri');
    $objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
    $activeSheet = $objPHPExcel->getActiveSheet();
    $activeSheet->setTitle('Compte de resultat systeme normal');
    //********************//   
    // Header du document //
    //********************//
    $objDrawing = new PHPExcel_Worksheet_Drawing();
            $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
            $objDrawing->setName('Entete');
            $objDrawing->setDescription('Entete');
            $objDrawing->setPath('../img1/entete.jpg');
            $objDrawing->setCoordinates('A2');
            $objDrawing->setOffsetX(110);
            $objDrawing->setRotation(25);
            $objDrawing->getShadow()->setVisible(true);
            $objDrawing->getShadow()->setDirection(45);
           
            $activeSheet->setCellValue('A4',utf8_encode("Compte de resultat systeme normal"));
            $activeSheet->mergeCells('A2:D2');
     
            // Body document PHPExcel
    $activeSheet->setCellValueByColumnAndRow(0, 9, "Ref");
    $activeSheet->setCellValueByColumnAndRow(1, 9, "CHARGES");
    $activeSheet->setCellValueByColumnAndRow(2, 9, "Exercice N");
    $activeSheet->setCellValueByColumnAndRow(3, 9, "");
    $activeSheet->setCellValueByColumnAndRow(4, 9, "Ref");
    $activeSheet->setCellValueByColumnAndRow(5, 9, "PRODUITS");
    $activeSheet->setCellValueByColumnAndRow(6, 9, "Exercice N");
    $activeSheet->getStyle('A9:G9')->applyFromArray(
        array(
            'font' => array('bold' => true),
            'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER),
            'borders'=>array('allborders'=>array('style'=>PHPExcel_Style_Border::BORDER_THIN)),
            'fill'=>array('type'=>PHPExcel_Style_Fill::FILL_SOLID,'color'=>array('argb'=>'#00FF33'))
        )
    );
    $activeSheet->getStyle('A9:G9')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
      $activeSheet->setCellValueByColumnAndRow(0, $ligne, utf8_encode(""));
        $activeSheet->setCellValueByColumnAndRow(1, $ligne, utf8_encode("ACTIVITE D'EXPLOITATION"));
        $activeSheet->setCellValueByColumnAndRow(2, $ligne, utf8_encode(""));
        $activeSheet->setCellValueByColumnAndRow(3, $ligne, utf8_encode(""));
        $activeSheet->setCellValueByColumnAndRow(4, $ligne, utf8_encode("ACTIVITE D'EXPLOITATION"));
        $activeSheet->setCellValueByColumnAndRow(5, $ligne, utf8_encode(""));
        $activeSheet->setCellValueByColumnAndRow(6, $ligne, utf8_encode(""));
       
   
        $activeSheet->setCellValueByColumnAndRow(0, $ligne, utf8_encode("RA"));
        $activeSheet->setCellValueByColumnAndRow(1, $ligne, utf8_encode("toto"));
        $activeSheet->setCellValueByColumnAndRow(2, $ligne, 50000);
        $activeSheet->setCellValueByColumnAndRow(3, $ligne, utf8_encode(""));
        $activeSheet->setCellValueByColumnAndRow(4, $ligne, utf8_encode("TA"));
        $activeSheet->setCellValueByColumnAndRow(5, $ligne, utf8_encode("sisi"));
        $activeSheet->setCellValueByColumnAndRow(6, $ligne, 5698222);
      

    $activeSheet->getColumnDimension('A')->setWidth(6);
    $activeSheet->getColumnDimension('B')->setWidth(40);
    $activeSheet->getColumnDimension('C')->setWidth(12);
    $activeSheet->getColumnDimension('D')->setWidth(10);
    $activeSheet->getColumnDimension('E')->setWidth(6);
    $activeSheet->getColumnDimension('F')->setWidth(40);
    $activeSheet->getColumnDimension('G')->setWidth(12);

$date = date("Y_m_d_H.i.s");
$nomFichier = "Cpt_rslt_".$date;
    // Génération du document en version Excel5
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        $objWriter->setPreCalculateFormulas(false);  

 
 
ob_clean();
        header('Content-type:application/vnd.ms-excel');
        header('Content-Disposition:inline;filename='.$nomFichier.'.xls');
        header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
        $objWriter->save('php://output');
?>