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

(Some) Unicode characters cause broken XLS file with missing cell content #465

Closed
fghber opened this issue Apr 12, 2018 · 2 comments
Closed

Comments

@fghber
Copy link

fghber commented Apr 12, 2018

This is (most probably) a bug report:

What is the expected behavior?

Get a valid and correctly populated XLS file

What is the current behavior?

Get a broken file, missing cell content

What are the steps to reproduce?

<?php
require __DIR__ . '/vendor/autoload.php';
/* normally the data is pass-over from a web page
$string = $_POST['String']; // comma-separated string: contains the entire table data (including the header)
$report = explode(",", $string);
$cols = count($titles) + 1;
*/
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$cols = 9;
$table = [
['1', 'Id No.', 'Stage', 'Status', 'Process No.', 'Process State', 'State Changed', 'JICS', 'JICS Sent Date'],
['92', '33134', 'ACPTD', 'New', '3', '📫', 'Wed Mar 21 2018 16:33:00 GMT-0700 (Pacific Daylight Time)', '✔️', 'Wed Mar 14 2018 00:00:00 GMT-0700 (Pacific Daylight Time)'],
['408','24134','CANCL','Returning','3','📫','Thu Mar 08 2018 12:32:00 GMT-0800 (Pacific Standard Time)','✔️','Mon Dec 28 2015 00:00:00 GMT-0800 (Pacific Standard Time)']
];
//$table = array_chunk($report, $cols);
$sheet->fromArray($table, null, 'A1');

//boilerplate code to download the file..
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.date('Ydm').'_Export.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
exit;

If there is 📫 the spreadsheet is broken:

xdebug://debug-eval:1: $table
array (size=3)
  0 => 
    array (size=9)
      0 => string '1' (length=1)
      1 => string 'Id No.' (length=6)
      2 => string 'Stage' (length=5)
      3 => string 'Status' (length=6)
      4 => string 'Process No.' (length=11)
      5 => string 'Process State' (length=13)
      6 => string 'State Changed' (length=13)
      7 => string 'JICS' (length=4)
      8 => string 'JICS Sent Date' (length=14)
  1 => 
    array (size=9)
      0 => string '92' (length=2)
      1 => string '33134' (length=5)
      2 => string 'ACPTD' (length=5)
      3 => string 'New' (length=3)
      4 => string '3' (length=1)
      5 => string '📫' (length=4)
      6 => string 'Wed Mar 21 2018 16:33:00 GMT-0700 (Pacific Daylight Time)' (length=57)
      7 => string '✔️' (length=6)
      8 => string 'Wed Mar 14 2018 00:00:00 GMT-0700 (Pacific Daylight Time)' (length=57)
  2 => 
    array (size=9)
      0 => string '408' (length=3)
      1 => string '24134' (length=5)
      2 => string 'CANCL' (length=5)
      3 => string 'Returning' (length=9)
      4 => string '3' (length=1)
      5 => string '📫' (length=4)
      6 => string 'Thu Mar 08 2018 12:32:00 GMT-0800 (Pacific Standard Time)' (length=57)
      7 => string '✔️' (length=6)
      8 => string 'Mon Dec 28 2015 00:00:00 GMT-0800 (Pacific Standard Time)' (length=57)

Which versions of PhpSpreadsheet and PHP are affected?

PHP 5.6.33, phpoffice/phpspreadsheet 1.2.1 (installed via composer)

@stale
Copy link

stale bot commented Jun 11, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Jun 11, 2018
@stale stale bot closed this as completed Jun 18, 2018
@oleibman
Copy link
Collaborator

Fixed by PR #3696 in August 2023.

@oleibman oleibman removed the stale label Jul 11, 2024
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