Skip to content

Fixed #201 when no 'r' attribute in node c in xlsx's xml #225

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

Merged
merged 3 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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

Expand Down
7 changes: 7 additions & 0 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ public function load($pFilename)
}

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']));
Expand All @@ -865,8 +866,12 @@ public function load($pFilename)
$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;
Expand Down Expand Up @@ -963,7 +968,9 @@ public function load($pFilename)
$cell->setXfIndex(isset($styles[(int) ($c['s'])]) ?
(int) ($c['s']) : 0);
}
$rowIndex += 1;
}
$cIndex += 1;
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/XLSXTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PHPUnit_Framework_TestCase;

class XLSXTest extends PHPUnit_Framework_TestCase
{
/**
* Test load Xlsx file without cell reference.
*/
public function testLoadXlsxWithoutCellReference()
{
$filename = './data/Reader/XLSX/without_cell_reference.xlsx';
$reader = new Xlsx();
$reader->load($filename);
}
}
Binary file not shown.