You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,22 @@ and this project adheres to [Semantic Versioning](https://semver.org).
10
10
### Added
11
11
12
12
- Implementation of the ISREF() information function.
13
-
-Allow Boolean Conversion in Csv Reader to be locale-aware when using the String Value Binder.
13
+
-Added support for reading "formatted" numeric values from Csv files; although default behaviour of reading these values as strings is preserved.
14
14
15
-
(i.e. `"Vrai"` wil be converted to a boolean `true` if the Locale is set to `fr`.)
15
+
(i.e a value of "12,345.67" will be read as numeric `1235.67`, not as a string `"12,345.67"`.
16
+
17
+
This functionality is locale-aware, using the server's locale settings to identify the thousands and decimal separators.
16
18
17
19
### Changed
18
20
19
21
- Gnumeric Reader now loads number formatting for cells.
20
22
- Gnumeric Reader now correctly identifies selected worksheet.
21
23
- Some Refactoring of the Ods Reader, moving all formula and address translation from Ods to Excel into a separate class to eliminate code duplication and ensure consistency.
24
+
- Make Boolean Conversion in Csv Reader locale-aware when using the String Value Binder.
25
+
26
+
This is determined b the Calculation Engine locale setting.
27
+
28
+
(i.e. `"Vrai"` wil be converted to a boolean `true` if the Locale is set to `fr`.)
Copy file name to clipboardExpand all lines: docs/topics/reading-files.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -560,6 +560,44 @@ Xlsx | NO | Xls | NO | Xml | NO |
560
560
Ods | NO | SYLK | NO | Gnumeric | NO |
561
561
CSV | YES | HTML | NO
562
562
563
+
564
+
### Reading formatted Numbers from a CSV File
565
+
566
+
Unfortunately, numbers in a CSV file may be formatted as strings.
567
+
If that number is a simple integer or float (with a decimal `.` separator) without any thousands separator, then it will be treated as a number.
568
+
However, if the value has a thousands separator (e.g. `12,345`), or a decimal separator that isn't a `.` (e.g. `123,45` for a European locale), then it will be loaded as a string with that formatting.
569
+
If you want the Csv Reader to convert that value to a numeric when it loads the file, the you need to tell it to do so. The `castFormattedNumberToNumeric()` lets you do this.
570
+
571
+
(Assuming that our server is configured with German locale settings: otherwise it may be necessary to call `setlocale()` before loading the file.)
572
+
```php
573
+
$inputFileType = 'Csv';
574
+
$inputFileName = './sampleData/example1.de.csv';
575
+
576
+
/** It may be necessary to call setlocale() first if this is not your default locale */
577
+
// setlocale(LC_ALL, 'de_DE.UTF-8', 'deu_deu');
578
+
579
+
/** Create a new Reader of the type defined in $inputFileType **/
/** Enable loading numeric values formatted with German , decimal separator and . thousands separator **/
582
+
$reader->castFormattedNumberToNumeric(true);
583
+
584
+
/** Load the file to a Spreadsheet Object **/
585
+
$spreadsheet = $reader->load($inputFileName);
586
+
```
587
+
This will attempt to load those formatted numeric values as numbers, based on the server's locale settings.
588
+
589
+
If you want to load those values as numbers, but also to retain the formatting as a number format mask, then you can pass a boolean `true` as a second argument to the `castFormattedNumberToNumeric()` method to tell the Reader to identify the format masking to use for that value. This option does have an arbitrary limit of 6 decimal places.
590
+
591
+
If your Csv file includes other formats for numbers (currencies, scientific format, etc); then you should probably also use the Advanced Value Binder to handle these cases.
0 commit comments