From e60054f3c41902f9a54f38eecc90257532dcbb53 Mon Sep 17 00:00:00 2001 From: madflow Date: Fri, 18 Mar 2016 22:39:27 +0100 Subject: [PATCH] More explicit rule for ignoring empty placeholder cells in Excel ODS #184 --- src/Spout/Reader/ODS/RowIterator.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Spout/Reader/ODS/RowIterator.php b/src/Spout/Reader/ODS/RowIterator.php index 5bd216b..44f5d2c 100644 --- a/src/Spout/Reader/ODS/RowIterator.php +++ b/src/Spout/Reader/ODS/RowIterator.php @@ -20,6 +20,7 @@ class RowIterator implements IteratorInterface const XML_NODE_TABLE = 'table:table'; const XML_NODE_ROW = 'table:table-row'; const XML_NODE_CELL = 'table:table-cell'; + const MAX_COLUMNS_EXCEL= 16384; /** Definition of XML attribute used to parse data */ const XML_ATTRIBUTE_NUM_COLUMNS_REPEATED = 'table:number-columns-repeated'; @@ -134,15 +135,16 @@ class RowIterator implements IteratorInterface return; } - // Only add value if the last read cell is not empty or does not need to repeat cell values. + // Only add the value if the last read cell is not a trailing empty cell repeater in Excel. + // The current count of read columns is determined my counting the the values in $rowData. // This is to avoid creating a lot of empty cells, as Excel adds a last empty "" // with a number-columns-repeated value equals to the number of (supported columns - used columns). - // In Excel, the number of supported columns is 16384, but we don't want to returns rows with always 16384 cells. - if (!$this->isEmptyCellValue($cellValue) || $numColumnsRepeated === 1) { + // In Excel, the number of supported columns is 16384, but we don't want to returns rows with + // always 16384 cells. + if ((count($rowData) + $numColumnsRepeated) !== self::MAX_COLUMNS_EXCEL) { for ($i = 0; $i < $numColumnsRepeated; $i++) { $rowData[] = $cellValue; } - $this->numReadRows++; } break;