Skip to content

Commit

Permalink
Fixes #310 (#311)
Browse files Browse the repository at this point in the history
* Fixes #310

* Update tests/IssuesTest.php

---------

Co-authored-by: Matej Jurančič <[email protected]>
Co-authored-by: Raphaël Huchet <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2023
1 parent 249da96 commit 05bc956
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Exportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions src/FastExcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'];
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/IssuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 05bc956

Please sign in to comment.