Skip to content

[BUG] Encoding bug with £(pound) sign #1738

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

Closed
ukenpachi opened this issue Dec 1, 2020 · 2 comments
Closed

[BUG] Encoding bug with £(pound) sign #1738

ukenpachi opened this issue Dec 1, 2020 · 2 comments

Comments

@ukenpachi
Copy link

ukenpachi commented Dec 1, 2020

This is:

- [*] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

$sheetData = [
Code,
Price (£),
Description
]

What is the current behavior?

my csv file headers looks like "Code,Qty,Price (£),Description,RRP,Ean" what I find is that "Price (£)" is replaced with "false" the array looks like "Code,Qty,false,Description,RRP,Ean" It only does this with the pound sign, the dollar or euro is fine.

$sheetData = [
Code,
false,
Description
]

What are the steps to reproduce?

csv file

Code,Qty,Price (£),Description,RRP,Ean
01,10.15,Size 12 L

$spreadsheet = PhpOffice\PhpSpreadsheet\IOFactory::load($csvFile);
$worksheet = $spreadsheet->getAllSheets();
$sheetCount = $spreadsheet->getSheetCount();
for ($i = 0; $i < $sheetCount; $i++) {
    $sheet = $spreadsheet->getSheet($i);
    $sheetData = $sheet->toArray(null, true, false, false); //this is where the issue is at
}


### Which versions of PhpSpreadsheet and PHP are affected?
1.15.0
@oleibman
Copy link
Collaborator

oleibman commented Dec 1, 2020

I believe this is a problem with the encoding of your file. When the csv file has been save as UTF-8 with BOM, PhpSpreadsheet and Excel read it correctly. However, when it is saved as CP1252 (which is sort of the default), Excel reads it correctly but PhpSpreadsheet produces the result you report. UTF-8 without BOM - PhpSpreadsheet correct, Excel not. However, if you know your file has been saved as CP1252, PhpSpreadsheet can still give you the desired result:

        $reader = new PhpOffice\PhpSpreadsheet\Reader\Csv();
        $reader->setInputEncoding('CP1252');
        $spreadsheet = $reader->load($csvFile);

I also have submitted PR #1717 which allows you to give PhpSpreadsheet the opportunity to guess the encoding.

@oleibman
Copy link
Collaborator

No update in almost a year. Believe the suggestion addresses the issue.

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

No branches or pull requests

2 participants