iliaal / php_excel

PHP Extension interface to the Excel writing/reading library
http://ilia.ws
534 stars 131 forks source link

Setting of NumberFormat? #191

Closed wengkiat closed 7 years ago

wengkiat commented 7 years ago

Hi,

I am creating an excel and have used :

$numFormat = new \ExcelFormat($excel); $numFormat->numberFormat(\ExcelFormat:: NUMFORMAT_GENERAL); $xlsSheet->write($rowNumber, $colNum, $row[$param], $numFormat);

But my value filled into the excel is text instead of a number, i would like a number.

I have tried: NUMFORMAT_NUMBER NUMFORMAT_TEXT

Please advise, thanks!

johmue commented 7 years ago

Testet with PHP7 on Win - not reproducible. I think $row[$param] is of type string and needs to be casted to float first.

$excel = new \ExcelBook();
$xlsSheet = new \ExcelSheet($excel, 'test');

$numFormat = new \ExcelFormat($excel);
$numFormat->numberFormat(\ExcelFormat::NUMFORMAT_GENERAL);
$xlsSheet->write(2, 1, 100, $numFormat);

$excel->save('foo.xls');
wengkiat commented 7 years ago

@johmue , alright casting to float did fix the problem, thanks!