public function XLSXExporter::compile in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/XLSXExporter.php \AKlump\LoftDataGrids\XLSXExporter::compile()
Build $this->output in prep for export/save
This is the main method to be extended for the different exporters
Overrides Exporter::compile
1 call to XLSXExporter::compile()
- XLSXExporter::save in vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ XLSXExporter.php - Save as a file to the server
File
- vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ XLSXExporter.php, line 101
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++;
}
}
}