/** * Format a single column with a number format * * You must do this after calling $this->compile! * * @param string $column * @param string $format_code * - USD OR PHPExcel_Style_NumberFormat::setFormatCode() * * @return $this */ 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); }