/** * Export des echantillons issus de la recherche en xls */ public function actionExportXls() { $model = new Sample('search'); $model->unsetAttributes(); if (isset($_GET['Sample'])) { $model->attributes = $_GET['Sample']; } // reprend les critères de la dernière recherche $dataprovider = new EMongoDocumentDataProvider('Sample', array('criteria' => $_SESSION['criteria'], 'pagination' => array('pageSize' => CommonTools::XLS_EXPORT_NB))); // supprime la pagination pour exporter l'ensemble des echantillons // $echantillons = $dataprovider->data; $data = array(1 => array_keys($model->attributeExportedLabels())); setlocale(LC_ALL, 'fr_FR.UTF-8'); $nb = 0; foreach ($dataprovider->data as $ech) { $line = array(); foreach (array_keys($model->attributeExportedLabels()) as $attribute) { if ($attribute != 'notes') { if ($ech->{$attribute} != null && !empty($ech->{$attribute})) { $line[] = trim(iconv('UTF-8', 'ASCII//TRANSLIT', $ech->{$attribute})); // solution la moins pire qui ne fait pas bugge les accents mais les convertit en caractere generique } else { $line[] = "-"; } } else { foreach ($ech->{$attribute} as $noteValue) { $line[] = trim(iconv('UTF-8', 'ASCII//TRANSLIT', $noteValue->key . ' : ' . $noteValue->value)); } } } $data[] = $line; } Yii::import('application.extensions.phpexcel.JPhpExcel'); $xls = new JPhpExcel('UTF-8', true, 'Sample list'); $xls->addArray($data); $xls->generateXML('sample list'); }