Export to excel in Symfony 1.4

0

I'm working with Symfony 1.4 and I have a problem. Following a query, a view is generated that shows the data of a person and their cars. This data I want to export to excel. It works well for me, except that, if that person has more than one car, he only shows me one (the last one). I would rather show the name and surname of the person, a car and under as many rows of excel sheets as cars have.

I pass the code to you

 action.class.php --> esta es la funcion de executeBatchExport



   $objPHPExcel = new PHPExcel();


      $campos = array(
        "Nombre y Apellido",
        "DNI",
        "Codigo Auto",
        "Fecha Compra",
        "Modelo",
        "Color",
        "Patente"
      );


      $columnas = array("A","B","C","D","E","F","G");
      $ids = $request->getParameter('ids');
      $q = Doctrine_Query::create()
              ->from('Titulares')
              ->whereIn('id', $ids);
      $q->whereIn("{$q->getRootAlias()}.id");
      $listaSolicitudes = $q->execute();



      // Add some data
      $objPHPExcel->setActiveSheetIndex(0);

      foreach ($campos as $indice => $campo) {
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnas[$indice] . '1', $campo);
      }

      $i = 2;
      $adic = '';
      foreach ($clientes as  $cliente) {
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$i, $cliente->getApellidoNombre() ? $cliente->getApellidoNombre(): '-');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, $cliente->getDni() ? $cliente->getDni() : '-');
        $autos= $cliente->getAuto();
        $filteredCollection = new Doctrine_Collection("Autos");
        foreach ($autos as $auto) {
          $objPHPExcel->setActiveSheetIndex(0)->setCellValue('D'.$i, $auto->getAutoCodigo() ? $auto->getAutoCodigo() : '-');
          $objPHPExcel->setActiveSheetIndex(0)->setCellValue('F'.$i, $auto->getModelo() ? $auto->getModelo() : '-');

// other fields of the car             }           }           // Rename worksheet           $ objPHPExcel-> getActiveSheet () - > setTitle ('Autos');

      // Set active sheet index to the first sheet, so Excel opens this as the first sheet
      $objPHPExcel->setActiveSheetIndex(0);

      // Redirect output to a client’s web browser (Excel5)
      header('Content-Type: application/vnd.ms-excel');
      header('Content-Disposition: attachment;filename="solicitudes-' . date("d-m-Y") . '.xls"');
      header('Cache-Control: max-age=0');
      // If you're serving to IE 9, then the following may be needed
      header('Cache-Control: max-age=1');

      // If you're serving to IE over SSL, then the following may be needed
      header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
      header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
      header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
      header ('Pragma: public'); // HTTP/1.0

      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
      $objWriter->save('php://output');
      exit;

What I want to achieve is, for example

    
asked by Maria Emilia 12.04.2018 в 22:00
source

1 answer

1

It is already solved, it was as simple as adding a counter before the second foreach to increase the number of cells this is the code:

$a=2;
foreach ($autos as $auto) {
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D'.$a
    
answered by 12.04.2018 в 22:34