I want to use "replace" formula to set value in excel. My code generates more than 16 digit number which I am not able to write in PHPExcel. (Excel do not support to write more than 16 digits as a number, it convert last digit to 'zero'. If I want to add 16 digit number, I need to convert the number type to text). So I use concat function in mysql which returns me 1234567890123456 digit number to '1234567890123456

When I generate excel file it return with single quote attach with excel. I assume that replace function will be useful.

$id = "'1234567890123456";
$objPHPExcel->getActiveSheet()->setCellValue('A2', '=REPLACE("'.$id.'"|1|1|)');

It doesn't work at all. Am I doing wrong?

有帮助吗?

解决方案

It's perfectly possible to write large numeric values in PHPExcel as strings, without having to resort to using formulae:

$id = "1234567890123456";
$objPHPExcel->getActiveSheet()
    ->setCellValueExplicit('A2', $id);

setCellValue() will set the datatype for the cell to numeric; but setCellValueExplicit() allows you to specify a datatype as a third argument - it defaults to PHPExcel_Cell_DataType::TYPE_STRING, so in this case you don't need to pass that argument

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top