Phpspreadsheet: Can not set empty enclosure for CSV

Created on 4 Jun 2020  路  6Comments  路  Source: PHPOffice/PhpSpreadsheet

This is:

- [x] a bug report
- [ ] a feature request
- [x] **not** a usage question

What is the expected behavior?

When enclosure is set to empty string, no enclosure should be written to CSV.

What is the current behavior?

Empty enclosure is changed to double quotes in PhpOffice\PhpSpreadsheet\Writer\Csv::setEnclosure(). Code was recently changed from

if ($pValue == '') {
    $pValue = null;
}
$this->enclosure = $pValue;

to

$this->enclosure = $pValue ? $pValue : '"';

and now changes empty string to double quotes.

What are the steps to reproduce?

<?php

require __DIR__ . '/vendor/autoload.php';

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet);
$writer->setEnclosure('');

Which versions of PhpSpreadsheet and PHP are affected?

1.13.0
Change has not been documented in the Changelog.

Most helpful comment

@oleibman are there any plans to merge it back any time soon?

All 6 comments

My apologies - it was my pull request that introduced this change. It did not break any existing tests. and I don't understand your use case. Can you please give me a testable example of how you are using this so that I can revert this behavior and add an appropriate test.

I am actually using Laravel Excel, where the CSV configuration parameters are only passed to phpspreadsheet.
Basically all I want to do is generate a CSV file without enclosures, such as this:

2020-06-03;000123;06.53;14.22
2020-06-03;000234;07.12;15.44
...

I used to achieve this using $writer->setEnclosure('');, but this now sets enclosure to " and I get such content:

"2020-06-03";"000123";"06.53";"14.22"
"2020-06-03";"000234";"07.12";"15.44"
...

_CSV files that my app generates are imported in another app. That app doesn't allow enclosures so files can't be imported. I know ..._ :roll_eyes:

@oleibman are there any plans to merge it back any time soon?

I would love an update for plans to merge for this as well.

Temporarily downgrading to 1.12.0 solves the issue

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals

  • Downgrading phpoffice/phpspreadsheet (1.13.0 => 1.12.0): Loading from cache
Was this page helpful?
0 / 5 - 0 ratings

Related issues

PowerKiKi picture PowerKiKi  路  5Comments

alexbog8 picture alexbog8  路  4Comments

huichen2017 picture huichen2017  路  4Comments

noxidsoft picture noxidsoft  路  3Comments

garnold picture garnold  路  5Comments