Skip to content

Commit

Permalink
Autodetect csv delimiter when not explicitly defined on imports
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrouwers committed Feb 28, 2022
1 parent 85f2ee1 commit 9493633
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [3.1.37] - 2022-02-28

### Fixed
- Add `@mixin` docblock to all macroable classes to allow for IDE autocompletion of delegate classes
- Fix issue with `Excel::toArray` not allowing nullable reader types for uploaded files

### Changed
- Change default Csv Import to auto-detect the delimiter when not explicitly defined

## [3.1.36] - 2022-02-03

### Fixed
- Fix return type of `FromQuery::query()`

## Changed
- Support Laravel 9
- Added a config setting to specify DB connection
- Added a config setting to specify CSV output encoding
Expand Down Expand Up @@ -196,8 +207,9 @@ All notable changes to this project will be documented in this file.
- Raw() method now also available on Exportable.
- Fix for breaking changes in PhpSpreadsheet with empty enclosures.

[Unreleased]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.36...HEAD
[3.1.35]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.35...3.1.36
[Unreleased]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.37...HEAD
[3.1.37]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.36...3.1.37
[3.1.36]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.35...3.1.36
[3.1.35]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.34...3.1.35
[3.1.34]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.33...3.1.34
[3.1.33]: https://github.com/Maatwebsite/Laravel-Excel/compare/3.1.32...3.1.33
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"require-dev": {
"orchestra/testbench": "^6.0|^7.0",
"predis/predis": "^1.1"
"predis/predis": "^1.1",
"laravel/legacy-factories": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion config/excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
|
*/
'csv' => [
'delimiter' => ',',
'delimiter' => null,
'enclosure' => '"',
'escape_character' => '\\',
'contiguous' => false,
Expand Down
36 changes: 36 additions & 0 deletions tests/Concerns/WithCustomCsvSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ public function getCsvSettings(): array
$this->assertStringContains('A2;åßàèòìù', $contents);
}

/**
* @test
*/
public function can_read_csv_with_auto_detecting_delimiter()
{
$import = new class implements WithCustomCsvSettings, ToArray
{
/**
* @return array
*/
public function getCsvSettings(): array
{
return [
'delimiter' => null,
'enclosure' => '',
'escape_character' => '\\',
'contiguous' => true,
'input_encoding' => 'UTF-8',
];
}

/**
* @param array $array
*/
public function array(array $array)
{
Assert::assertEquals([
['A1', 'B1'],
['A2', 'B2'],
], $array);
}
};

$this->SUT->import($import, 'csv-with-other-delimiter.csv');
}

/**
* @test
*/
Expand Down

0 comments on commit 9493633

Please sign in to comment.