Make CSV Reader boolean casting (e.g. string ``"TRUE"` to boolean `TRUE`) locale-aware.
This commit is contained in:
parent
fe969f59cc
commit
5579712688
|
|
@ -37,9 +37,7 @@ $spreadsheet->getActiveSheet()
|
||||||
### Creating a new Cell
|
### Creating a new Cell
|
||||||
|
|
||||||
If you make a call to `getCell()`, and the cell doesn't already exist, then
|
If you make a call to `getCell()`, and the cell doesn't already exist, then
|
||||||
PhpSpreadsheet will (by default) create the cell for you. If you don't want
|
PhpSpreadsheet will create that cell for you.
|
||||||
to create a new cell, then you can pass a second argument of false, and then
|
|
||||||
`getCell()` will return a null if the cell doesn't exist.
|
|
||||||
|
|
||||||
### BEWARE: Cells assigned to variables as a Detached Reference
|
### BEWARE: Cells assigned to variables as a Detached Reference
|
||||||
|
|
||||||
|
|
@ -532,7 +530,7 @@ types of entered data using a cell's `setValue()` method (the
|
||||||
Optionally, the default behaviour of PhpSpreadsheet can be modified,
|
Optionally, the default behaviour of PhpSpreadsheet can be modified,
|
||||||
allowing easier data entry. For example, a
|
allowing easier data entry. For example, a
|
||||||
`\PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder` class is available.
|
`\PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder` class is available.
|
||||||
It automatically converts percentages, number in scientific format, and
|
It automatically converts percentages, numbers in scientific format, and
|
||||||
dates entered as strings to the correct format, also setting the cell's
|
dates entered as strings to the correct format, also setting the cell's
|
||||||
style information. The following example demonstrates how to set the
|
style information. The following example demonstrates how to set the
|
||||||
value binder in PhpSpreadsheet:
|
value binder in PhpSpreadsheet:
|
||||||
|
|
@ -577,7 +575,9 @@ $stringValueBinder->setNumericConversion(false)
|
||||||
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( $stringValueBinder );
|
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( $stringValueBinder );
|
||||||
```
|
```
|
||||||
|
|
||||||
**Creating your own value binder is relatively straightforward.** When more specialised
|
### Creating your own value binder
|
||||||
|
|
||||||
|
Creating your own value binder is relatively straightforward. When more specialised
|
||||||
value binding is required, you can implement the
|
value binding is required, you can implement the
|
||||||
`\PhpOffice\PhpSpreadsheet\Cell\IValueBinder` interface or extend the existing
|
`\PhpOffice\PhpSpreadsheet\Cell\IValueBinder` interface or extend the existing
|
||||||
`\PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder` or
|
`\PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder` or
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Reader;
|
namespace PhpOffice\PhpSpreadsheet\Reader;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||||
use PhpOffice\PhpSpreadsheet\Reader\Csv\Delimiter;
|
use PhpOffice\PhpSpreadsheet\Reader\Csv\Delimiter;
|
||||||
|
|
@ -353,9 +354,9 @@ class Csv extends BaseReader
|
||||||
private function convertBoolean(&$rowDatum, bool $preserveBooleanString): void
|
private function convertBoolean(&$rowDatum, bool $preserveBooleanString): void
|
||||||
{
|
{
|
||||||
if (is_string($rowDatum) && !$preserveBooleanString) {
|
if (is_string($rowDatum) && !$preserveBooleanString) {
|
||||||
if (strcasecmp('true', $rowDatum) === 0) {
|
if (strcasecmp(Calculation::getTRUE(), $rowDatum) === 0 || strcasecmp('true', $rowDatum) === 0) {
|
||||||
$rowDatum = true;
|
$rowDatum = true;
|
||||||
} elseif (strcasecmp('false', $rowDatum) === 0) {
|
} elseif (strcasecmp(Calculation::getFALSE(), $rowDatum) === 0 || strcasecmp('false', $rowDatum) === 0) {
|
||||||
$rowDatum = false;
|
$rowDatum = false;
|
||||||
}
|
}
|
||||||
} elseif ($rowDatum === null) {
|
} elseif ($rowDatum === null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue