setCellValue of Stirng returns a number

Topics: Developer Forum
Feb 20, 2015 at 3:54 PM
Hi,
I've a string as "2015." (finished by a dot).

When I use of setCellValue (with or without formatting), the result is alaways the same.

The value Inside the celle is the number 2015

The dot is lost somewhere, and I got a number.

Do I do something wrong ?

Cheers
Coordinator
Feb 20, 2015 at 3:58 PM
Because PHP treats 2015. as a valid number, assuming that the . is a decimal point, and that you simply have no decimal digits following

The solution is to use setCellValueExplicit() instead, which defaults to treating the value as a string
Feb 20, 2015 at 4:04 PM
Hi Mark,

Thank you.

I'll try it right now.

Cheers
Feb 20, 2015 at 4:25 PM
Hi Mark,

Sorry, but I did what you wrote and the setCellValueExplicit() treat as the same manner as setCellValue()

Cheers
Coordinator
Feb 20, 2015 at 7:53 PM
I find that difficult to believe: unless you've found a major bug in PHPExcel that I have been unable to replicate.

The following code:
$objPHPExcel = new PHPExcel();
$value = "2015.";
$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1', $value);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('test.xls');
generates a spreadsheet that looks like:
"2015." in Spreadsheet
Mar 12, 2015 at 5:10 PM
Hi Mark,

So sorry to be late.

I wasn't able to answer.

So sorry too, 'cause it's works fine, just a mistake I did with my file's name.

So thank you again
Cheers