diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ee38170..e399d3e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Control characters in cell values are automatically escaped - [#212](https://github.com/PHPOffice/PhpSpreadsheet/issues/212) - Prevent color changing when copy/pasting xls files written by PhpSpreadsheet to another file - @al-lala [#218](https://github.com/PHPOffice/PhpSpreadsheet/issues/218) +- Add cell reference automatic when there is no cell reference('r' attribute) in Xlsx file. - @GreatHumorist [#225](https://github.com/PHPOffice/PhpSpreadsheet/pull/225) Refer to [issue#201](https://github.com/PHPOffice/PhpSpreadsheet/issues/201) ### BREAKING CHANGE diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 5b4b3e92..8958e465 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -848,6 +848,7 @@ class Xlsx extends BaseReader implements IReader } if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) { + $cIndex = 1; // Cell Start from 1 foreach ($xmlSheet->sheetData->row as $row) { if ($row['ht'] && !$this->readDataOnly) { $docSheet->getRowDimension((int) ($row['r']))->setRowHeight((float) ($row['ht'])); @@ -865,8 +866,12 @@ class Xlsx extends BaseReader implements IReader $docSheet->getRowDimension((int) ($row['r']))->setXfIndex((int) ($row['s'])); } + $rowIndex = 0; // Start form zero because Cell::stringFromColumnIndex start from A default, actually is 1 foreach ($row->c as $c) { $r = (string) $c['r']; + if ($r == '') { + $r = Cell::stringFromColumnIndex($rowIndex) . $cIndex; + } $cellDataType = (string) $c['t']; $value = null; $calculatedValue = null; @@ -963,7 +968,9 @@ class Xlsx extends BaseReader implements IReader $cell->setXfIndex(isset($styles[(int) ($c['s'])]) ? (int) ($c['s']) : 0); } + $rowIndex += 1; } + $cIndex += 1; } } diff --git a/tests/PhpSpreadsheetTests/Reader/XLSXTest.php b/tests/PhpSpreadsheetTests/Reader/XLSXTest.php new file mode 100644 index 00000000..aab9c6ea --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/XLSXTest.php @@ -0,0 +1,19 @@ +load($filename); + } +} diff --git a/tests/data/Reader/XLSX/without_cell_reference.xlsx b/tests/data/Reader/XLSX/without_cell_reference.xlsx new file mode 100644 index 00000000..99e5f1d4 Binary files /dev/null and b/tests/data/Reader/XLSX/without_cell_reference.xlsx differ