Question

I am using PhPExcel to export to a spreadsheet, and am getting the following error in the numbers column in Excel:

The number in this cell is formatted as text or preceded by an apostrophe

I have searched on here extensively, and tried several solutions to fix this. The following line is what outputs the numbers:

$objPHPExcel->getActiveSheet()->setCellValue('D'.$excel_row, show_currency($aGenericAmenity['price']));

The closest I could get to an answer via my search was:

 $objPHPExcel->getActiveSheet()->setCellValueExplicit('D'.$excel_row, show_currency($aGenericAmenity['price'], PHPExcel_Cell_DataType::TYPE_STRING));

but that did not work. I am not a programmer, so any help is appreciated.

Was it helpful?

Solution

Set the value as a straight number, and use a format mask to display it as currency

$objPHPExcel->getActiveSheet()
    ->setCellValue('D'.$excel_row, $aGenericAmenity['price']);
$objPHPExcel->getActiveSheet()
    ->getStyle('D'.$excel_row)
    ->getNumberFormat()
    ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);

There's plenty examples showing how to do this, and it's described in the documentation as well

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top