Skip to content

Commit 5579712

Browse files
author
MarkBaker
committed
Make CSV Reader boolean casting (e.g. string `"TRUE" to boolean TRUE) locale-aware.
1 parent fe969f5 commit 5579712

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

docs/topics/accessing-cells.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ $spreadsheet->getActiveSheet()
3737
### Creating a new Cell
3838

3939
If you make a call to `getCell()`, and the cell doesn't already exist, then
40-
PhpSpreadsheet will (by default) create the cell for you. If you don't want
41-
to create a new cell, then you can pass a second argument of false, and then
42-
`getCell()` will return a null if the cell doesn't exist.
40+
PhpSpreadsheet will create that cell for you.
4341

4442
### BEWARE: Cells assigned to variables as a Detached Reference
4543

@@ -532,7 +530,7 @@ types of entered data using a cell's `setValue()` method (the
532530
Optionally, the default behaviour of PhpSpreadsheet can be modified,
533531
allowing easier data entry. For example, a
534532
`\PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder` class is available.
535-
It automatically converts percentages, number in scientific format, and
533+
It automatically converts percentages, numbers in scientific format, and
536534
dates entered as strings to the correct format, also setting the cell's
537535
style information. The following example demonstrates how to set the
538536
value binder in PhpSpreadsheet:
@@ -577,7 +575,9 @@ $stringValueBinder->setNumericConversion(false)
577575
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( $stringValueBinder );
578576
```
579577

580-
**Creating your own value binder is relatively straightforward.** When more specialised
578+
### Creating your own value binder
579+
580+
Creating your own value binder is relatively straightforward. When more specialised
581581
value binding is required, you can implement the
582582
`\PhpOffice\PhpSpreadsheet\Cell\IValueBinder` interface or extend the existing
583583
`\PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder` or

src/PhpSpreadsheet/Reader/Csv.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Reader;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
56
use PhpOffice\PhpSpreadsheet\Cell\Cell;
67
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
78
use PhpOffice\PhpSpreadsheet\Reader\Csv\Delimiter;
@@ -353,9 +354,9 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
353354
private function convertBoolean(&$rowDatum, bool $preserveBooleanString): void
354355
{
355356
if (is_string($rowDatum) && !$preserveBooleanString) {
356-
if (strcasecmp('true', $rowDatum) === 0) {
357+
if (strcasecmp(Calculation::getTRUE(), $rowDatum) === 0 || strcasecmp('true', $rowDatum) === 0) {
357358
$rowDatum = true;
358-
} elseif (strcasecmp('false', $rowDatum) === 0) {
359+
} elseif (strcasecmp(Calculation::getFALSE(), $rowDatum) === 0 || strcasecmp('false', $rowDatum) === 0) {
359360
$rowDatum = false;
360361
}
361362
} elseif ($rowDatum === null) {

0 commit comments

Comments
 (0)