diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index f36366e3..5c623fa5 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -172,8 +172,6 @@ class Csv extends BaseReader implements IReader $this->skipBOM(); $this->checkSeparator(); - $escapeEnclosures = ['\\' . $this->enclosure, $this->enclosure . $this->enclosure]; - $worksheetInfo = []; $worksheetInfo[0]['worksheetName'] = 'Worksheet'; $worksheetInfo[0]['lastColumnLetter'] = 'A'; @@ -246,11 +244,6 @@ class Csv extends BaseReader implements IReader } $sheet = $spreadsheet->setActiveSheetIndex($this->sheetIndex); - $escapeEnclosures = [ - '\\' . $this->enclosure, - $this->enclosure . $this->enclosure, - ]; - // Set our starting row based on whether we're in contiguous mode or not $currentRow = 1; if ($this->contiguous) { @@ -262,9 +255,6 @@ class Csv extends BaseReader implements IReader $columnLetter = 'A'; foreach ($rowData as $rowDatum) { if ($rowDatum != '' && $this->readFilter->readCell($columnLetter, $currentRow)) { - // Unescape enclosures - $rowDatum = str_replace($escapeEnclosures, $this->enclosure, $rowDatum); - // Convert encoding if necessary if ($this->inputEncoding !== 'UTF-8') { $rowDatum = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($rowDatum, 'UTF-8', $this->inputEncoding); diff --git a/tests/PhpSpreadsheetTests/Reader/CsvTest.php b/tests/PhpSpreadsheetTests/Reader/CsvTest.php new file mode 100644 index 00000000..ee092eb2 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/CsvTest.php @@ -0,0 +1,27 @@ +'; + $filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet'); + + // Write temp file with value + $spreadsheet = new Spreadsheet(); + $spreadsheet->getActiveSheet()->getCell('A1')->setValue($value); + $writer = new \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet); + $writer->save($filename); + + // Read written file + $reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv(); + $reloadedSpreadsheet = $reader->load($filename); + $actual = $reloadedSpreadsheet->getActiveSheet()->getCell('A1')->getCalculatedValue(); + $this->assertSame($value, $actual, 'should be able to write and read strings with multiples quotes'); + } +}