public function renderTable(TableContent $content) { $style = array('header:border' => $this->convertColor(array(200, 200, 200)), 'header:background' => $this->convertColor(array(200, 200, 200)), 'header:text' => $this->convertColor(array(255, 255, 255)), 'body:background' => $this->convertColor(array(255, 255, 255)), 'body:stripe' => $this->convertColor(array(250, 250, 250)), 'body:border' => $this->convertColor(array(200, 200, 200)), 'body:text' => $this->convertColor(array(0, 0, 0))); if ($content->getAsTotalsBox()) { $totals = $content->getData(); for ($i = 0; $i < $this->numColumns; $i++) { $this->worksheet->setCellValueByColumnAndRow($i, $this->row, $totals[$i]); $this->worksheet->getStyleByColumnAndRow($i, $this->row)->getFont()->setBold(true); $this->worksheet->getStyleByColumnAndRow($i, $this->row)->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK)->getColor()->setRGB($style['body:border']); } } else { $headers = $content->getHeaders(); $this->numColumns = count($headers); $col = 0; foreach ($headers as $header) { $this->worksheet->setCellValueByColumnAndRow($col, $this->row, str_replace("\\n", "\n", $header)); $this->worksheet->getStyleByColumnAndRow($col, $this->row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $this->worksheet->getStyleByColumnAndRow($col, $this->row)->getFill()->getStartColor()->setRGB($style['header:background']); $this->worksheet->getStyleByColumnAndRow($col, $this->row)->getFont()->setBold(true)->getColor()->setRGB($style['header:text']); $col++; } $fill = false; $types = $content->getDataTypes(); $widths = $content->getTableWidths(); foreach ($content->getData() as $rowData) { $this->row++; $col = 0; $this->renderRow($rowData, $types, $style, $fill); $fill = !$fill; } } $this->row++; }
public function renderTable(TableContent $content) { $templates = array('widths' => $content->getTableWidths(), 'as_totals_box' => $content->getAsTotalsBox(), 'num_columns' => $content->getNumColumns(), 'data' => $content->getData(), 'headers' => $content->getHeaders(), 'auto_totals' => $content->getAutoTotals(), 'types' => $content->getDataTypes()); if ($templates['auto_totals']) { $templates['totals'] = $content->getTotals(); } $this->markup .= TemplateEngine::render(__DIR__ . '/html_templates/table.tpl', $templates); }
/** * Draws a report table. This method could be overriden in subclasses to * present another means of presenting data. The method returns the total * values of the table in an array form based on the data parameters. * * @param array $data The data to be displayed * @param array $params Special parameters attached to the parameters * @param array $dataParams More parameters * @param mixed $totalTable The object to use as the instance of the totals table * @param string $heading A special heading for the table if it is a nested table * @return array */ protected function drawTable($data, $params, &$dataParams, $totalTable, $heading) { $paramsCopy = $params; if (is_array($params["ignored_fields"])) { foreach ($params["ignored_fields"] as $ignored) { unset($paramsCopy["headers"][$ignored]); unset($paramsCopy["data_params"]["type"][$ignored]); unset($paramsCopy["data_params"]["total"][$ignored]); unset($paramsCopy["data_params"]["widths"][$ignored]); } $paramsCopy["headers"] = array_values($paramsCopy["headers"]); $paramsCopy["data_params"]["type"] = array_values($paramsCopy["data_params"]["type"]); $paramsCopy["data_params"]["total"] = array_values($paramsCopy["data_params"]["total"]); $paramsCopy["data_params"]["widths"] = array_values($paramsCopy["data_params"]["widths"]); $this->widths = $paramsCopy["data_params"]["widths"]; $this->dataParams = $paramsCopy["data_params"]; foreach ($data as $key => $row) { foreach ($params["ignored_fields"] as $ignored) { unset($data[$key][$ignored]); //$data[$key] = array_values($row); } } } $table = new TableContent($paramsCopy["headers"], $data, $paramsCopy["data_params"]); if ($totalTable == true) { $table->style["autoTotalsBox"] = true; } if ($this->widths == null) { $this->widths = $table->getTableWidths(); } $params["report"]->add($table); $total = $table->getTotals(); return $total; }