Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel Style getting default number format

Tags:

php

phpexcel

I have the following code

$xl = new PHPExcel();
$sheet = xl->setActiveSheetIndex(0)
$sheet->getStyle('A')->getNumberFormat()->setFormatCode('#,##0.00');
$format = $sheet->getStyle('A')->getNumberFormat()->getFormatCode();

I'd expect $format to contain #,##0.00 but it contains General.

Am I missing something?

PHPExcel v. 1.7.6

like image 916
hectorh30 Avatar asked Jan 16 '14 18:01

hectorh30


1 Answers

PHPExcel does not support row or column styles: styles are applied to cells

$sheet->getStyle('A1')->getNumberFormat()->setFormatCode('#,##0.00');

or to ranges of cells

$sheet->getStyle('A1:B2')->getNumberFormat()->setFormatCode('#,##0.00');

and version 1.7.6 is very dated now, you really should upgrade to a more recent version

like image 129
Mark Baker Avatar answered Nov 15 '22 05:11

Mark Baker