<?php 
    $arrayData = $data['data'];
    $optionsReport = $this->getOptions();
    
    $colTitulos[] = 'Customer';
    $colTitulos[] = 'Phone';
    $colTitulos[] = 'Product';
    $colTitulos[] = 'Quantity';
    $colTitulos[] = 'Amount';
    $colTitulos[] = 'Store';
    
    $objPHPExcel = new PHPExcel();
    $sheet = $objPHPExcel->getActiveSheet();
    $sheet->freezePane('A3');
    $col = count($colTitulos);
    $lastCol = $this->getColLetter($col-1);    
    
    $sheet->mergeCells("A1:".$lastCol."1");            
    $sheet->getRowDimension('1')->setRowHeight(50);
    $sheet->getStyle("A1")->getFont()->setBold(true);
    $sheet->setCellValue("A1", $this->headerExcelReport);
    $sheet->getStyle('A1')->getAlignment()->setWrapText(true);
    $sheet->getStyle("A1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $sheet->getStyle("A1")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);      
    
    $sheet->getStyle("A2:".$lastCol."2")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $sheet->getStyle("A2:".$lastCol."2")->getFont()->setBold(true);
    $sheet->fromArray($colTitulos,NULL,'A2');    
    
    $row=3;
    $firstRow = $row;    
   foreach ($arrayData as $key => $data) {              
        $sheet->setCellValue("A$row", $data['customer_name']);                          
        $sheet->setCellValue("B$row", $data['phone']);                                 
        $sheet->setCellValue("C$row", $data['product']);       
        $sheet->setCellValue("D$row", $data['quantity']);         
        $sheet->setCellValue("E$row", $data['amount']);  
        $sheet->setCellValue("F$row", $data['store']);  
        
        $row++;        
    }
    $sheet->getStyle("A$firstRow:$lastCol$row")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    
    foreach(range('A',$lastCol) as $columnID) {
        $sheet->getColumnDimension($columnID)
            ->setAutoSize(true);
    }

    $objPHPExcel->setActiveSheetIndex(0);   
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    
    if($this->saveFile == true){
        $objWriter->save($this->getTempFolder()."/".$this->getNombreArchivo().".xlsx");
    }else{                
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header("Content-Disposition: attachment;filename=".$this->getNombreArchivo().".xlsx");
        header('Cache-Control: max-age=0');
        $objWriter->save('php://output');
        exit;
    }
    unset($objWriter);