public function XLSXExporter::formatColumn 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::formatColumn()
Format a single column with a number format
You must do this after calling $this->compile!
Parameters
string $column:
string $format_code:
Return value
$this
Overrides Exporter::formatColumn
File
- vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ XLSXExporter.php, line 169
Class
- XLSXExporter
- Class XLSXExporter
Namespace
AKlump\LoftDataGridsCode
public function formatColumn($column, $format_code) {
// By default we'll use USD.
$format_code = isset($format_code) ? $format_code : 'USD';
$phpexcel_format = \PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
// Map to specific formats in PHPExcel
if ($format_code === 'USD') {
$phpexcel_format = \PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
}
elseif ($format_code === \PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE) {
$format_code = 'USD';
}
$columns = $this
->getPHPExcelColumns();
if (!array_key_exists($column, $columns)) {
return;
}
$phpexcel_column = $columns[$column];
$page = $this->excel
->getActiveSheet();
foreach ($page
->getRowIterator() as $row) {
$row_index = $row
->getRowIndex();
$page
->getStyle("{$phpexcel_column}{$row_index}")
->getNumberFormat()
->setFormatCode($phpexcel_format);
}
return parent::formatColumn($column, $format_code);
}