Skip to content

Commit

Permalink
Additional Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman committed Oct 18, 2023
1 parent 3275e57 commit 4818f62
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/PhpSpreadsheet/Reader/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class Csv extends BaseReader
Expand Down Expand Up @@ -106,6 +105,10 @@ class Csv extends BaseReader

private string $getFalse = 'false';

private string $thousandsSeparator = ',';

private string $decimalSeparator = '.';

/**
* Create a new CSV Reader instance.
*/
Expand Down Expand Up @@ -397,6 +400,8 @@ private function loadStringOrFile(string $filename, Spreadsheet $spreadsheet, bo
$preserveBooleanString = method_exists($valueBinder, 'getBooleanConversion') && $valueBinder->getBooleanConversion();
$this->getTrue = Calculation::getTRUE();
$this->getFalse = Calculation::getFALSE();
$this->thousandsSeparator = StringHelper::getThousandsSeparator();
$this->decimalSeparator = StringHelper::getDecimalSeparator();
while (is_array($rowData)) {
$noOutputYet = true;
$columnLetter = 'A';
Expand Down Expand Up @@ -461,18 +466,18 @@ private function convertBoolean(mixed &$rowDatum): void
*/
private function convertFormattedNumber(mixed &$rowDatum): string
{
$numberFormatMask = NumberFormat::FORMAT_GENERAL;
$numberFormatMask = '';
if ($this->castFormattedNumberToNumeric === true && is_string($rowDatum)) {
$numeric = str_replace(
[StringHelper::getThousandsSeparator(), StringHelper::getDecimalSeparator()],
[$this->thousandsSeparator, $this->decimalSeparator],
['', '.'],
$rowDatum
);

if (is_numeric($numeric)) {
$decimalPos = strpos($rowDatum, StringHelper::getDecimalSeparator());
$decimalPos = strpos($rowDatum, $this->decimalSeparator);
if ($this->preserveNumericFormatting === true) {
$numberFormatMask = (str_contains($rowDatum, StringHelper::getThousandsSeparator()))
$numberFormatMask = (str_contains($rowDatum, $this->thousandsSeparator))
? '#,##0' : '0';
if ($decimalPos !== false) {
$decimals = strlen($rowDatum) - $decimalPos - 1;
Expand Down

0 comments on commit 4818f62

Please sign in to comment.