Cell Format

Topics: Developer Forum
Oct 28, 2010 at 2:38 AM



Is there a chance to configure a cell to avoid auto-formatting?

Although I saved all cells' formatting settings to be "Text", not a formatted number, not a date or other... After .setCellValue some of the cells which do not have a string inside, but a high number, are converted into date or other malformed data.

Why does Excel or phpexcel overwrite my original cell formatting settings? How to prevent this behaviour through phpexcel?



Nov 2, 2010 at 12:01 AM

PHPExcel uses a Value Binder when data is written to a cell using the setValue() method. The default Value Binder can be found in Classes/PHPExcel/Cell/DefaultValueBinder.php and the dataTypeForValue() attempts to identify an appropriate datatype.

If you want to change this behaviour, then either use setValueExplicit() rather than setValue(); or write your own Value Binder to override the Default Value Binder. You can then use

PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_MyPersonalValueBinder() );

to enable your binder rules.