我有这个简单的要求:
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对象 ( [code_postal] => 7134 [nom_ville] => RESSAIX )
和此通知:
注意:尝试在第561行的/home/web998/public_html/classes/Excel/Classes/impression_xlsx_demandes_agrements.php中获取非对象的属性
注意:尝试在第562行的/home/web998/public_html/classes/Excel/Classes/impression_xlsx_demandes_agrements.php中获取非对象的属性
第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 :(得分:0)
我想你要将数据导出到excel。
您是否使用excel类创建了对象$objPHPExcel = new Excel();
。