I'm trying to create another worksheet and everything works fine. But what I need now is to create 1 depending on a variable. For instance :
I have two options one for validation and one for results.
Everything is conditioned by a boolean variable called $resultado
.
I have my component in CakePHP
function ExcelCargaMasivaComponent() {
$this->xls = new PHPExcel();
$this->sheet = $this->xls->getActiveSheet();
$this->sheet->setTitle("Worksheet");
$this->sheet->getDefaultStyle()->getFont()->setName('Verdana');
$this->xls->createSheet();
$this->xls->setActiveSheetIndex(1);
$this->validations = $this->xls->getActiveSheet();
$this->validations->setTitle('Validations');
}
Where this-> validations is the second worksheet. Now, I need this worksheet has a different name, and therefore I want other data encapsulated in a function. So my function generate wanted condition this way:
function ExcelCargaMasivaComponent() {
$this->xls = new PHPExcel();
$this->sheet = $this->xls->getActiveSheet();
$this->sheet->setTitle("Worksheet");
$this->sheet->getDefaultStyle()->getFont()->setName('Verdana');
$this->xls->createSheet();
$this->xls->setActiveSheetIndex(1);
}
function generate($title = 'Report', $headers = array(), $data = array(), $uid = false, $resultados = false){
if($resultados){
$this->validations = $this->xls->getActiveSheet();
$this->validations->setTitle('Resultados');
}else{
$this->validations = $this->xls->getActiveSheet();
$this->validations->setTitle('Validations');
}
}
I do this so that the second sheet has a different name and different data depending on the variable, but I could not get it to work. I only generates 1 sheet with the title depending on the variable, it's not what I want.