2015-09-06 67 views
0

當我有這個簡單的請求:通知使用對象

if($donnees->pays == 1) 
{ 
    $sql = "SELECT code_postal, nom as nom_ville FROM localite_be WHERE id = ".$donnees->code_postal_off; 
} 
elseif($donnees->pays == 2) 
{ 
    $sql = "SELECT code_postal, nom as nom_ville FROM localite_fr WHERE id = ".$donnees->code_postal_off; 

} 
else 
{ 
    $sql = "SELECT code_postal, nom as nom_ville FROM localite_lux WHERE id = ".$donnees->code_postal_off; 
} 
$cp_ville = $bdd->prepare($sql); 
$cp_ville->execute(); 

$res_cp_ville = $cp_ville->fetch(PDO::FETCH_OBJ); 

我獲得的對象:

stdClass的對象 ( [code_postal] => 7060 [nom_ville] =>蘇瓦尼 )

stdClass Object ( [code_postal] => 7134 [nom_ville] => RESSAIX )

和此通知:

說明:試圖獲得非對象的屬性在/ home/web998 /的public_html /類/上線的Excel /班/ impression_xlsx_demandes_agrements.php 561

注意:試圖讓非對象的財產/home/web998/public_html/classes/Excel/Classes/impression_xlsx_demandes_agrements.php線562

線561和562的優勢如下:

$objPHPExcel->getActiveSheet()->SetCellValue('G'.$i, $res_cp_ville->code_postal); 
$objPHPExcel->getActiveSheet()->SetCellValue('H'.$i, $res_cp_ville->nom_ville); 


echo "<pre>"; 
print_r($res_cp_ville); 
echo "</pre>"; 

這是整個代碼:您要

//je crée une nouvelle sheet Excel 
    $objPHPExcel->createSheet(); 
    //je la mets en active 
    $objPHPExcel->setActiveSheetIndex(1)->setTitle('Demandes de renouvellements'); 

    //Demandes de renouvellements 
    $sql = "SELECT pharmacien.*, 
        officine.ref_type_officine, 
        officine.telephone, 
        officine.mail, 
        officine.province, 
        officine.adresse as addr_off, 
        pays.libelle, 
        province_be.nom as prov, 
        officine.ref_code_postal as code_postal_off 
      FROM pharmacien 
      LEFT JOIN agrement 
      ON pharmacien.ref_agrement = agrement.id 
      LEFT JOIN officine 
      ON pharmacien.ref_identification = officine.ref_identification 
      LEFT JOIN pays 
      ON pharmacien.pays = pays.id 
      LEFT JOIN province_be 
      ON officine.province = province_be.ID 
      WHERE (date_soumission IS NOT NULL AND ref_type_agrement = '2' ) 
      "; 


    //echo $sql; 
    $pharmaciens = $bdd->prepare($sql); 
    $pharmaciens->execute(); 

    $res = $pharmaciens->fetchAll(PDO::FETCH_OBJ); 

    $i = 2; 
    $temp_nombre_jours = 0; 
    $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'NOM'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('B1', 'PRENOM'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'TYPE OFFICINE'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('D1', 'PAYS'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('E1', 'PROVINCE'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('F1', 'ADRESSE OFFICINE'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('G1', 'CP OFFICINE'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('H1', 'VILLE OFFICINE'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('I1', 'TELEPHONE'); 
    $objPHPExcel->getActiveSheet()->SetCellValue('J1', 'MAIL'); 

    foreach($res as $donnees) 
    { 
    $styleArray = array('font' => array('bold' => true)); 

    //je mets en gras le contenu de ces cellules 
    $objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('B1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('C1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('D1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('E1')->applyFromArray($styleArray); 

    $objPHPExcel->getActiveSheet()->getStyle('F1')->applyFromArray($styleArray); 

    $objPHPExcel->getActiveSheet()->getStyle('G1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('H1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('I1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('J1')->applyFromArray($styleArray); 
    $objPHPExcel->getActiveSheet()->getStyle('K1')->applyFromArray($styleArray); 

    $objPHPExcel->getActiveSheet()->SetCellValue('A'.$i, $donnees->nom); 
    $objPHPExcel->getActiveSheet()->SetCellValue('B'.$i, $donnees->prenom); 


    if($donnees->ref_type_officine == 1) 
    { 
     $objPHPExcel -> getActiveSheet() -> setCellValue('C'.$i, 'Officine ouverte au public');  
    } 
    else 
    { 
     $objPHPExcel -> getActiveSheet() -> setCellValue('C'.$i, 'Officine hospitaliere');  
    } 

    //pays 
    if($donnees->pays == 1) 
    { 
     $objPHPExcel->getActiveSheet()->SetCellValue('D'.$i, "BELGIQUE");  
    } 
    elseif($donnees->pays == 2) 
    { 
     $objPHPExcel->getActiveSheet()->SetCellValue('D'.$i, "FRANCE");  
    } 
    else 
    { 
     $objPHPExcel->getActiveSheet()->SetCellValue('D'.$i, "LUXEMBOURG");  
    } 

    //province 
    $objPHPExcel->getActiveSheet()->setCellValue('E'.$i, $donnees->prov); 


    $objPHPExcel->getActiveSheet()->setCellValue('F'.$i, $donnees->addr_off); 

    if($donnees->pays == 1) 
    { 
     $sql = "SELECT code_postal, nom as nom_ville FROM localite_be WHERE id = ".$donnees->code_postal_off; 
    } 
    elseif($donnees->pays == 2) 
    { 
     $sql = "SELECT code_postal, nom as nom_ville FROM localite_fr WHERE id = ".$donnees->code_postal_off; 

    } 
    else 
    { 
     $sql = "SELECT code_postal, nom as nom_ville FROM localite_lux WHERE id = ".$donnees->code_postal_off; 
    } 
    $cp_ville = $bdd->prepare($sql); 
    $cp_ville->execute(); 

    $res_cp_ville = $cp_ville->fetch(PDO::FETCH_OBJ); 

    $objPHPExcel->getActiveSheet()->SetCellValue('G'.$i, $res_cp_ville->code_postal); 
    $objPHPExcel->getActiveSheet()->SetCellValue('H'.$i, $res_cp_ville->nom_ville); 



    $objPHPExcel->getActiveSheet()->SetCellValue('I'.$i, $donnees->telephone); 
    $objPHPExcel->getActiveSheet()->SetCellValue('J'.$i, $donnees->mail); 


    $i = $i+1; 
    }//fin du foreach 

    //redimensionnement des colonnes afin d'avoir des colonnes en autosize 
    for($col = 'A'; $col !== 'L'; $col++) 
    { 
     $objPHPExcel->getActiveSheet() 
     ->getColumnDimension($col) 
     ->setAutoSize(true); 
    } 
+0

該代碼應該工作。錯誤可能是由於其他原因:在兩行不同的代碼中寫入代碼: $ objPHPExcel-> getActiveSheet(){new line here} - > SetCellValue('G'。$ i,$ res_cp_ville-> code_postal) ; – gskhanal

回答

0

我的事情的數據導出到Excel。 你是否用你的excel類創建了對象$objPHPExcel = new Excel();

+0

我創建了它,是的。我添加了我的整個代碼,請參閱上面的內容。謝謝 – beegees