help me the question about percent

Topics: Developer Forum, Project Management Forum, User Forum
Jan 13, 2009 at 9:58 AM

I use this command in my program:
$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1','7.12%',PHPExcel_Cell_DataType::TYPE_NUMERIC);

But the problem is that:  Excel can't auto recognize the percentage as the NUMERIC type, instead, it uses as String.
I do not know why.

Can anyone tell me? And how can I solve this problem?

Thank you!

 

Developer
Jan 13, 2009 at 10:31 AM
You will want to do like this:

$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1', 0.0712, PHPExcel_Cell_DataType::TYPE_NUMERIC);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);

Screen shot:
http://img369.imageshack.us/img369/8789/percentjo4.png