Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: Changing delimiter in CSV exporter does not effect the first row (headers) #14855

Closed
mgambella opened this issue Apr 24, 2024 · 2 comments

Comments

@mgambella
Copy link

mgambella commented Apr 24, 2024

What happened?

Description

I needed to change the delimiter for the CSV exporter from comma to semicolon, because it was messing up the data imports into Excel. I could find some reference to this issue by reading this file vendor/craftcms/cms/src/web/Response.php

Steps to reproduce

  1. create the file config/app.web.php with this content:
<?php

use craft\helpers\App;
use craft\helpers\ArrayHelper;
use craft\web\Response;

return [
    'components' => [
        'response' => fn() => Craft::createObject(ArrayHelper::merge(
            App::webResponseConfig(),
            [
                'defaultFormatters' => [
                    Response::FORMAT_CSV => [
                        'delimiter' => ';',
                    ],
                ],
            ]
        )),
    ],
];
  1. go to control panel to an element index and export data as CSV

Note: the issue could be related to the cms/src/web/CsvResponseFormatter.php line 108

if ($this->includeHeaderRow) {
    fputcsv($fp, $headers, ',');
}

instead, it should probably be:

if ($this->includeHeaderRow) {
    fputcsv($fp, $headers, $this->delimiter);
}

Expected behavior

Both the headers and data rows are delimited by the same delimiter char (a semicolon in my case).

Actual behavior

The header is still using a commas as delimiter.

Craft CMS version

4.8.10

PHP version

8.1

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

Thanks for reporting that! Fixed for the next v4 and v5 releases.

@brandonkelly
Copy link
Member

Craft 4.8.11 and 5.0.6 are out with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants