Support missing attribute `r` in `c` node when reading xlsx
When describing a cell, the cell reference (r="A1") is optional. When not present, we should just increment the index of the last processed row. Fixes #201 Closes #225
This commit is contained in:
parent
7aa6233185
commit
2abe56b946
|
@ -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)
|
- 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)
|
- 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
|
### BREAKING CHANGE
|
||||||
|
|
||||||
|
|
|
@ -848,6 +848,7 @@ class Xlsx extends BaseReader implements IReader
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) {
|
if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) {
|
||||||
|
$cIndex = 1; // Cell Start from 1
|
||||||
foreach ($xmlSheet->sheetData->row as $row) {
|
foreach ($xmlSheet->sheetData->row as $row) {
|
||||||
if ($row['ht'] && !$this->readDataOnly) {
|
if ($row['ht'] && !$this->readDataOnly) {
|
||||||
$docSheet->getRowDimension((int) ($row['r']))->setRowHeight((float) ($row['ht']));
|
$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']));
|
$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) {
|
foreach ($row->c as $c) {
|
||||||
$r = (string) $c['r'];
|
$r = (string) $c['r'];
|
||||||
|
if ($r == '') {
|
||||||
|
$r = Cell::stringFromColumnIndex($rowIndex) . $cIndex;
|
||||||
|
}
|
||||||
$cellDataType = (string) $c['t'];
|
$cellDataType = (string) $c['t'];
|
||||||
$value = null;
|
$value = null;
|
||||||
$calculatedValue = null;
|
$calculatedValue = null;
|
||||||
|
@ -963,7 +968,9 @@ class Xlsx extends BaseReader implements IReader
|
||||||
$cell->setXfIndex(isset($styles[(int) ($c['s'])]) ?
|
$cell->setXfIndex(isset($styles[(int) ($c['s'])]) ?
|
||||||
(int) ($c['s']) : 0);
|
(int) ($c['s']) : 0);
|
||||||
}
|
}
|
||||||
|
$rowIndex += 1;
|
||||||
}
|
}
|
||||||
|
$cIndex += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.
Loading…
Reference in New Issue