Search code examples
phpxlsxphpspreadsheet

How can I set a cell to TRUE|FALSE with PhpSpreadsheet?


I'm trying to set a cell value to TRUE or FALSE with PhpSpreadsheet 1.16.0, but the result is not what I want.

My code:

    $sheet->getCell('A1')
        ->setValueExplicit(true, DataType::TYPE_BOOL);

This is what I get when I open the file with LibreOffice Calc 7.0 or 7.1:

enter image description here

As you can see, the cell shows a formula =TRUE() (or =FALSE()) instead of the native XLSX "boolean" type.

The cell itself has type "Number", instead of the expected "Boolean Value":

enter image description here

This looks easy enough, but I can't figure it out what I'm doing wrong.


Solution

  • With Excel it works as expected. This is probably a bug in LibreOffice.

    https://github.com/PHPOffice/PhpSpreadsheet/issues/1833#issuecomment-777409629