Skip to content

Incorrect handling of EOL characters in cell values #347

@PowerGamer1

Description

@PowerGamer1

When spreadsheet is saved in OOXML file format CR character must be encoded according to ISO/IEC 29500-1 (Office Open XML File Formats Part 1) standard (as _x000D_) or XML standard (as 
).

When reading cell value from OOXML file PHPSpreadsheet file reader must decode _x000D_ into CR character (
 will be decoded automatically by PHP's XML reader used by PHPSpreadsheet file reader).

Microsoft Excel correctly handles CR character in cell values encoded either way (the character is not lost when resaving the XLSX file in Microsoft Excel).

What is the expected behavior?

CR character survive a round-trip through Xlsx and Open Office XML formats.

true
false

What is the current behavior?

CR character is lost after a round-trip through Xlsx and Open Office XML formats.

false
true

What are the steps to reproduce?

<?php
require __DIR__ . '/vendor/autoload.php';
$s1 = "AA\r\nAA";
$doc = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $doc->getSheet(0);
$sheet->getCellByColumnAndRow(1, 1)->setValueExplicit($s1, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($doc, 'Xlsx');
$writer->save('1.xlsx');

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$doc = $reader->load('1.xlsx');
$sheet = $doc->getSheet(0);
$s2 = $sheet->getCellByColumnAndRow(1, 1)->getValue();
var_dump($s2 === $s1);
var_dump($s2 === "AA\nAA");

Which versions of PhpSpreadsheet and PHP are affected?

1.0.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions