/**
  * @param ExportableInterface $adminList
  *
  * @return \PHPExcel_Writer_Excel2007
  *
  * @throws \Exception
  * @throws \PHPExcel_Exception
  */
 public function createExcelSheet(ExportableInterface $adminList)
 {
     $objPHPExcel = new \PHPExcel();
     $objWorksheet = $objPHPExcel->getActiveSheet();
     $number = 1;
     $row = array();
     foreach ($adminList->getExportColumns() as $column) {
         $row[] = $column->getHeader();
     }
     $objWorksheet->fromArray($row, null, 'A' . $number++);
     $iterator = $adminList->getIterator();
     foreach ($iterator as $item) {
         if (array_key_exists(0, $item)) {
             $itemObject = $item[0];
         } else {
             $itemObject = $item;
         }
         $row = array();
         foreach ($adminList->getExportColumns() as $column) {
             $data = $adminList->getStringValue($itemObject, $column->getName());
             if (is_object($data)) {
                 if (!$this->renderer->exists($column->getTemplate())) {
                     throw new \Exception('No export template defined for ' . get_class($data));
                 }
                 $data = $this->renderer->render($column->getTemplate(), array('object' => $data));
             }
             $row[] = $data;
         }
         $objWorksheet->fromArray($row, null, 'A' . $number++);
     }
     $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
     return $objWriter;
 }
 /**
  * @param ExportableInterface $adminList
  *
  * @return Response
  *
  * @throws \Exception
  */
 public function streamExcelSheet(ExportableInterface $adminList)
 {
     $response = new StreamedResponse();
     $response->setCallback(function () use($adminList) {
         $writer = WriterFactory::create(Type::XLSX);
         $writer->openToBrowser("export.xlsx");
         $row = array();
         foreach ($adminList->getExportColumns() as $column) {
             $row[] = $this->translator->trans($column->getHeader());
         }
         $writer->addRow($row);
         $iterator = $adminList->getIterator();
         $rows = array();
         foreach ($iterator as $item) {
             if (array_key_exists(0, $item)) {
                 $itemObject = $item[0];
             } else {
                 $itemObject = $item;
             }
             $row = array();
             foreach ($adminList->getExportColumns() as $column) {
                 $data = $adminList->getStringValue($itemObject, $column->getName());
                 if (is_object($data)) {
                     if (!$this->renderer->exists($column->getTemplate())) {
                         throw new \Exception('No export template defined for ' . get_class($data));
                     }
                     $data = $this->renderer->render($column->getTemplate(), array('object' => $data));
                 }
                 $row[] = $data;
             }
             $rows[] = $row;
         }
         $writer->addRows($rows);
         $writer->close();
     });
     return $response;
 }