Search code examples
phpformattingphpexcelpercentage

Formatting a cell to a percentage in PHPExcel


I am automating an excel spreadsheet using PHP.

I have been looking for a way to pragmatically format a cell to a percentage in PHPExcel.

I want to change a value like

0.077922078

to

8%

Is there a solution for this?

Thanks in advance.


Solution

  • assuming your cell is A1 ..

    $objPHPExcel->getActiveSheet()->getStyle('A1')
        ->getNumberFormat()->applyFromArray( 
            array( 
                'code' => PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00
            )
        );