/** * @param Worksheet $worksheet * @param array $style_h2 * @return Worksheet * @throws \PHPExcel_Exception */ public function exportExcel(Worksheet $worksheet, array $style_h2) { $last_row = $worksheet->getHighestDataRow(); $last_row += 2; $max_col = $worksheet->getHighestDataColumn(); $worksheet->mergeCells("A{$last_row}:{$max_col}{$last_row}"); $worksheet->setCellValue("A{$last_row}", utf8_encode($this->getTitulo())); $worksheet->getStyle("A{$last_row}:{$max_col}{$last_row}")->applyFromArray($style_h2); $worksheet->getRowDimension($last_row)->setRowHeight(20); $last_row += 2; $worksheet->setCellValue("C{$last_row}", utf8_encode('Opción')); $worksheet->setCellValue("D{$last_row}", 'Votos'); $first_row = $last_row; $last_row += 1; foreach ($this->getDatos() as $key => $dato) { $worksheet->setCellValue("B{$last_row}", $key + 1); $worksheet->setCellValue("C{$last_row}", utf8_encode($dato[0])); if (mb_strlen($dato[0]) > 45) { $worksheet->getRowDimension($last_row)->setRowHeight(27); } $worksheet->setCellValue("D{$last_row}", $dato[1]); $last_row++; } $last_row -= 1; $worksheet->getStyle("C{$first_row}:D{$last_row}")->applyFromArray($this->getEstiloTabla('center', true)); $first_row++; $worksheet->getStyle("B{$first_row}:D{$last_row}")->applyFromArray($this->getEstiloTabla()); $first_row -= 1; $top_chart = $first_row - 1; $bottom_chart = $first_row + 12; $chart1 = $this->getChart($first_row, $last_row, $top_chart, $bottom_chart); $worksheet->addChart($chart1); $worksheet->setCellValue("A{$bottom_chart}", ""); return $worksheet; }
/** * Set format for column * @param string $columnName * @param string $formatString * @return \Meridius\PhpExcel\Formatter */ private function formatColumn($columnName, $formatString) { $this->sheet->getStyle($columnName . '1:' . $columnName . $this->sheet->getHighestDataRow())->getNumberFormat()->setFormatCode($formatString); return $this; }
/** * Checks to see if the sheet is empty. * * @param \PHPExcel_Worksheet $sheet The PHPExcel sheet to check. * * @return bool Returns TRUE if the sheet is empty, else FALSE. */ private static function sheetIsEmpty(\PHPExcel_Worksheet $sheet) : bool { return $sheet->getHighestDataRow() === 1 && $sheet->getHighestDataColumn() === 'A' && $sheet->getCell('A1')->getValue() === null; }