use Galerie\Model\GalerieTable;
use Galerie\Model\GalerieInfoTable;
use Galerie\Form\GalerieForm;
+use Galerie\Export\GalerieWorkbook;
use Custom\View\Helper\Format;
$result->initialize();
return $result;
},
+ 'Galerie\Export\GalerieWorkbook' => function ($sm) {
+ return new GalerieWorkbook;
+ },
),
);
}
private $_galerieTable;
private $_galerieInfoTable;
private $_galerieForm;
+ private $_galerieInfoExporter;
private $_translator;
return $this->_galerieForm;
}
+ private function _getGalerieInfoExporter()
+ {
+ if (!$this->_galerieInfoExporter) {
+ $sm = $this->getServiceLocator();
+ $this->_galerieInfoExporter = $sm->get('Galerie\Export\GalerieWorkbook');
+ }
+ return $this->_galerieInfoExporter;
+ }
+
+
public function indexAction()
$response = $this->getResponse();
$response->setStatusCode(200);
+ // Modification des entêtes
$headers = $this->getResponse()->getHeaders();
$headers->addHeaderLine('Content-Type', 'text/csv; charset=utf-8');
$headers->addHeaderLine('Content-Disposition', 'attachment; filename="export_galerie.csv"');
-
$response->setContent(implode("\r\n", $content));
+
return $response;
}
+
+ public function excelAction() {
+ // Récupération des informations brutes
+ $modelManager = $this->_getGalerieInfoTable();
+ $datas = $modelManager->all();
+
+ $exporter = $this->_getGalerieInfoExporter();
+ $exporter->build($datas);
+
+ // Renvoi d'une réponse vide pour désactiver le rendu de la vue
+ return $this->getResponse();
+ }
+
+
public function listAction()
{
// Récupération de l'objet requête
--- /dev/null
+<?php
+
+namespace Galerie\Export;
+
+use Custom\Export\AbstractWorkbook;
+
+
+class GalerieWorkbook extends AbstractWorkbook
+{
+
+ /**
+ * Nom du fichier utilisé pour l'export.
+ *
+ * @return string
+ */
+ protected function nomFichier()
+ {
+ return 'export_galerie.xls';
+ }
+
+
+
+
+ /**
+ * Méthode d'écriture des données dans la feuille courante.
+ *
+ * @return null
+ */
+ protected function writeData()
+ {
+ $this->ecrireCaseCourante("Nom", 'titre_string');
+ $this->ecrireCaseCourante("Description", 'titre_string');
+ $this->ecrireCaseCourante("Propriétaire", 'titre_string');
+ $this->ecrireCaseCourante("Photos", 'titre_string');
+ $this->nextLine();
+ foreach($this->datas as $d) {
+ $this->ecrireCaseCourante($d->name, 'case_string');
+ $this->ecrireCaseCourante($d->description, 'case_string');
+ $this->ecrireCaseCourante($d->username, 'case_string');
+ $this->ecrireCaseCourante($d->nb, 'case_chiffre');
+ $this->nextLine();
+ }
+ }
+
+
+
+
+ /**
+ * Mise en forme après écriture.
+ *
+ * @return null
+ */
+ protected function postFormats()
+ {
+ $this->current_worksheet->setColumn(0, 0, '10');
+ $this->current_worksheet->setColumn(1, 1, '40');
+ $this->current_worksheet->setColumn(2, 2, '10');
+ $this->current_worksheet->setColumn(3, 3, '5');
+
+ $this->current_worksheet->setRow(0, 50);
+ $c = count($this->datas);
+ for($i=1;$i<=$c;$i++) {
+ $this->current_worksheet->setRow($i, 30);
+ }
+
+ $this->current_worksheet->setLandscape();
+ $this->current_worksheet->hideGridLines();
+ }
+
+}
+