From 5f6436cc703aac0380e9ca07e1aee4c7d02e6f2a Mon Sep 17 00:00:00 2001 From: Adrien Loison Date: Mon, 17 Oct 2016 10:46:47 -0700 Subject: [PATCH] ODS Reader should support num-rows-repeated for non empty rows --- src/Spout/Reader/ODS/RowIterator.php | 12 ++++-------- tests/Spout/Reader/ODS/ReaderTest.php | 13 +++++++++++++ .../ods/sheet_with_number_rows_repeated.ods | Bin 0 -> 2558 bytes 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 tests/resources/ods/sheet_with_number_rows_repeated.ods diff --git a/src/Spout/Reader/ODS/RowIterator.php b/src/Spout/Reader/ODS/RowIterator.php index 4051583..e85e4dd 100644 --- a/src/Spout/Reader/ODS/RowIterator.php +++ b/src/Spout/Reader/ODS/RowIterator.php @@ -131,13 +131,10 @@ class RowIterator implements IteratorInterface /** * Returns whether we need data for the next row to be processed. - * We don't need to read data if: - * we have already read at least one row - * AND - * we need to preserve empty rows - * AND - * the last row that was read is not the row that need to be processed - * (i.e. if we need to return empty rows) + * We DO need to read data if: + * - we have not read any rows yet + * OR + * - the next row to be processed immediately follows the last read row * * @return bool Whether we need data for the next row to be processed. */ @@ -147,7 +144,6 @@ class RowIterator implements IteratorInterface return ( !$hasReadAtLeastOneRow || - !$this->shouldPreserveEmptyRows || $this->lastRowIndexProcessed === $this->nextRowIndexToBeProcessed - 1 ); } diff --git a/tests/Spout/Reader/ODS/ReaderTest.php b/tests/Spout/Reader/ODS/ReaderTest.php index d8ec39b..77fd3d6 100644 --- a/tests/Spout/Reader/ODS/ReaderTest.php +++ b/tests/Spout/Reader/ODS/ReaderTest.php @@ -78,6 +78,19 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals([['foo']], $allRows); } + /** + * @return void + */ + public function testReadShouldSupportNumberRowsRepeated() + { + $allRows = $this->getAllRowsForFile('sheet_with_number_rows_repeated.ods'); + $expectedRows = [ + ['foo', 10.43], + ['foo', 10.43], + ]; + $this->assertEquals($expectedRows, $allRows); + } + /** * @return void */ diff --git a/tests/resources/ods/sheet_with_number_rows_repeated.ods b/tests/resources/ods/sheet_with_number_rows_repeated.ods new file mode 100644 index 0000000000000000000000000000000000000000..450148fd2e2d8286b61486dd8959955c5bd8b387 GIT binary patch literal 2558 zcmZ{m2{hDeAIHbU3{jMj-9^flsc@r^WEtxiOmCK3GDDUb?u=z9%h(wVvXd-XCz372 zG}NnI5|e$#nx!mF#+Kzy-FshM=f2PX{LgdF|9QT@=bZ2PeLw#PX10g(5C8z+28`NR zL+!m;hiE_mAe09H;AMYx@y7U~Fuup}Xs;^7Ys?@-pk+##lkRQ=`&%_kz z-jbkV-c<0@lKDafW1k5>R!t9jkf&Ts6~sj;JHH~OM?BmqaNC3+K_QD-->h0Gz50d^ zalC%G#t4!uARwVEa>T45+>8T!`DWX)kZ^viy-tBJsn4!csA=zhke3MDF$qoMD-<)1 z2dXfPFU)I;aI}=y6Lb&QPT3FX)9JIN$QHo-J(c z#SXkwylBpdh|jsvD4B_$@z1p_&<-^JJ^I~eVSm}lh~B*c3e((Y-6R=uE!u+UY|do^qX!qcU;O^~+-vX*6zM9;vN$1@J5D-^-#$# zU`aL=(P#s}&|=S4@yKCkW#`aP@{8F`$0Uj>*ptzFu?b*B%nun-?Li} z@TPZ6^hg)6Zbfk_Y1wvUR%$!7)3mQ7ZM(QOJ?GmeSr;YmC!SxMRu^v=tY$S|UO$^u zCeV@{g^l!F&P6FS=Rf{!>p}fG7woU@2LLd()=+lC|8KAZ0I)E$)mMdD8maxgjT>Nj zMcTN2KE`Q|y*$MZiqOy7(9RflR}}6?TpCi_Jf1@Mq8Ebqj$a>}(=<=5HQ+ttRW{FY z;chj^K{ExO^WgTW>Dm*T83w_%N4{*{ZtYk;7@k}{`h!O1j6-tQ$U$&7Wnk)IR1fXiMyvbE{-(u4`Po{{{0#?+j|Fxpm& z_uKRy1j;|F2QF?S zKxG55P8*>wMOtFB2R&Z~%Vy7E!jg{p2v)02gs&2F_u%aDUEMAX%AeO9l{wLN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