public function XLSXExporter::compile in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/XLSXExporter.php \AKlump\LoftDataGrids\XLSXExporter::compile()
Build the string content of $this->output and return $this for chaining.
Parameters
mixed $page_id: (Optional) Defaults to NULL. Set this to only compile a single page.
Return value
$this
Overrides ExporterInterface::compile
2 calls to XLSXExporter::compile()
- XLSXExporter::save in vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ XLSXExporter.php - Stream as a file to the server with headers.
- XLSXExporter::saveFile in vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ XLSXExporter.php - Compile and and save to a filepath.
File
- vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ XLSXExporter.php, line 92
Class
- XLSXExporter
- Class XLSXExporter
Namespace
AKlump\LoftDataGridsCode
public function compile($page_id = null) {
$pages = $this
->getData()
->get();
$this->output = !empty($pages);
foreach ($pages as $page_id => $data) {
if (empty($this->sheets)) {
$this->sheets[] = $page_id;
}
elseif (!in_array($page_id, $this->sheets)) {
$this->sheets[] = $page_id;
$this->excel
->createSheet();
}
// Assure our active sheet is an integar
$active_sheet = array_search($page_id, $this->sheets);
$this->excel
->setActiveSheetIndex($active_sheet);
$worksheet = $this->excel
->getActiveSheet();
//@todo The column count is wrong when sheets differ in the column count.
// Format the header row:
$header = $this
->getHeader($page_id);
// Format the rows:
$row_index = 1;
$worksheet
->fromArray($header, null, 'A' . $row_index++, true);
foreach ($data as $row) {
$col_index = 'A';
$worksheet
->fromArray($row, null, 'A' . $row_index, true);
$row_index++;
}
}
return $this;
}