From 05bc956fa6121b239c98960ea9b551116f20b058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Juran=C4=8Di=C4=8D?= Date: Thu, 9 Feb 2023 16:13:18 +0100 Subject: [PATCH] Fixes rap2hpoutre/fast-excel#310 (#311) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes rap2hpoutre/fast-excel#310 * Update tests/IssuesTest.php --------- Co-authored-by: Matej Jurančič Co-authored-by: Raphaël Huchet --- src/Exportable.php | 2 +- src/FastExcel.php | 9 +++++---- tests/IssuesTest.php | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Exportable.php b/src/Exportable.php index 46e794f..2854ff3 100644 --- a/src/Exportable.php +++ b/src/Exportable.php @@ -98,7 +98,7 @@ private function exportOrDownload($path, $function, callable $callback = null) $writer = new \OpenSpout\Writer\XLSX\Writer($options); } - $this->setOptions($writer); + $this->setOptions($options); /* @var \OpenSpout\Writer\WriterInterface $writer */ $writer->$function($path); diff --git a/src/FastExcel.php b/src/FastExcel.php index c534cbb..c09fdd7 100644 --- a/src/FastExcel.php +++ b/src/FastExcel.php @@ -4,9 +4,10 @@ use Generator; use Illuminate\Support\Collection; -use OpenSpout\Reader\CSV\Options; +use OpenSpout\Reader\CSV\Options as CsvReaderOptions; use OpenSpout\Reader\CSV\Reader; use OpenSpout\Reader\ReaderInterface; +use OpenSpout\Writer\CSV\Options as CsvWriterOptions; use OpenSpout\Writer\CSV\Writer; use OpenSpout\Writer\WriterInterface; @@ -187,13 +188,13 @@ public function configureWriterUsing(?callable $callback = null) */ protected function setOptions(&$reader_or_writer) { - if ($reader_or_writer instanceof Options || $reader_or_writer instanceof \OpenSpout\Writer\Common\Entity\Options) { + if ($reader_or_writer instanceof CsvReaderOptions || $reader_or_writer instanceof CsvWriterOptions) { $reader_or_writer->FIELD_DELIMITER = $this->csv_configuration['delimiter']; $reader_or_writer->FIELD_ENCLOSURE = $this->csv_configuration['enclosure']; - if ($reader_or_writer instanceof Options) { + if ($reader_or_writer instanceof CsvReaderOptions) { $reader_or_writer->ENCODING = $this->csv_configuration['encoding']; } - if ($reader_or_writer instanceof \OpenSpout\Writer\Common\Entity\Options) { + if ($reader_or_writer instanceof CsvWriterOptions) { $reader_or_writer->SHOULD_ADD_BOM = $this->csv_configuration['bom']; } } diff --git a/tests/IssuesTest.php b/tests/IssuesTest.php index a98f211..7c94277 100644 --- a/tests/IssuesTest.php +++ b/tests/IssuesTest.php @@ -168,4 +168,24 @@ public function testIssue104() 'Password' => 'asdadasdasdasdasd', ]); } + + public function testIssue310() + { + $original_collection = $this->collection(); + $delimiter = ';'; + $file = 'issue_310.csv'; + + (new FastExcel(clone $original_collection)) + ->configureCsv($delimiter) + ->export($file); + + $this->assertEquals( + $original_collection, + (new FastExcel()) + ->configureCsv($delimiter) + ->import($file) + ); + + unlink($file); + } }