From c954eddf5760891110c6fd7913de0b9e0ba6f0a2 Mon Sep 17 00:00:00 2001 From: Paolo Agostinetto Date: Mon, 20 Feb 2017 21:02:04 +0100 Subject: [PATCH] Ods reader: fix sheet count and added a test for sheet names --- src/PhpSpreadsheet/Reader/Ods.php | 4 +++- tests/PhpSpreadsheetTests/Reader/OdsTest.php | 21 +++++++++++++++---- tests/data/Reader/Ods/data.ods | Bin 11764 -> 11764 bytes 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index 2d44ee6c..e5c9c600 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -435,7 +435,9 @@ class Ods extends BaseReader implements IReader } // Create sheet - $spreadsheet->createSheet(); + if($worksheetID > 0){ + $spreadsheet->createSheet(); // First sheet is added by default + } $spreadsheet->setActiveSheetIndex($worksheetID); if ($worksheetName) { diff --git a/tests/PhpSpreadsheetTests/Reader/OdsTest.php b/tests/PhpSpreadsheetTests/Reader/OdsTest.php index 1b53278a..e71f52fd 100644 --- a/tests/PhpSpreadsheetTests/Reader/OdsTest.php +++ b/tests/PhpSpreadsheetTests/Reader/OdsTest.php @@ -13,9 +13,7 @@ use PhpOffice\PhpSpreadsheet\Reader\Ods; use PhpOffice\PhpSpreadsheet\Style\Font; /* - * @todo Fix sheet name (is not imported correctly) - * @todo Sheets count is incorrect - * @todo The class doesn't read the bold/italic/underline properties + * @todo The class doesn't read the bold/italic/underline properties (rich text) */ class OdsTest extends \PHPUnit_Framework_TestCase { @@ -61,13 +59,28 @@ class OdsTest extends \PHPUnit_Framework_TestCase return $this->spreadsheetData; } + public function testReadFileProperties() + { + $filename = __DIR__ . '/../../data/Reader/Ods/data.ods'; + + // Load into this instance + $reader = new Ods(); + + // Test "listWorksheetNames" method + + $this->assertEquals([ + "Sheet1", + "Second Sheet", + ], $reader->listWorksheetNames($filename)); + } + public function testLoadWorksheets() { $spreadsheet = $this->loadDataFile(); $this->assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet); -// $this->assertCount(1, $spreadsheet->getAllSheets()); + $this->assertEquals(2, $spreadsheet->getSheetCount()); $firstSheet = $spreadsheet->getSheet(0); $this->assertInstanceOf('PhpOffice\PhpSpreadsheet\Worksheet', $firstSheet); diff --git a/tests/data/Reader/Ods/data.ods b/tests/data/Reader/Ods/data.ods index 5f58d457a42c0a1c5655d6d4b889402425b25a5a..3171eb6b7e31487b89848a91b89cae9adaa7ad35 100644 GIT binary patch delta 1162 zcmewo{Uw?wz?+#xgn@yBf#LeXi9A6}*B5R~xXTZuCff@r)ZY(&WF=C!zn=B-b!#uj zquk1GL|RzGV;8bU-glDrI%e`xMbrMz>-<}XUR}Gk_Cm$?b1%9toBTZY@@4tH$ud-DVSYw`^w(6_b%Gsntm-_yu{AkEXU#spN+>6!FHz;ntN2H z3*YO=H{aSYk&RX6BO7DA+!NkJ^A-Fj^CBNVedCs*BNv(MA~*Y%6UY8Qz4c+MA74Fb zn3}gUX#Mrm7w_H;nLWv}=<}?u^!+BTntwAjVg#&(C0D=tm1()}npd=Xe9N*`TgwV> z*w(#H%2xPS-ooErLzVd**(~-vP z7b?C7Lw{L!UGpg0=quO$FzbQJo+nM7Oc`q@@J%hRlxkA@v!#LO#Cw^)rJbBlmj)Y& z3v|ioykY4HE_1gOGU8m8sd)acNWS9#dJTb{{*qOTTo`hGNpwoTI`G6hBA|@ntfKIV zu-17W>ckf)UH-E4Ki3D|=mn}h7u*|mNIqQoj(y+f?Flb$9qilG^3>r@l4?!+tz}LD z>m44jd)ay~5;^rkpoFPlf=h34%zbmV1FZ`W?dy!YEqo{D!qxD$Nsnw7i#R)MnU=ul zdBocKzPv!(U$AK3wu5>RSKRwUL?4FRxzs zR`9^af3JDZ!i#nLfJ3X zH_E)j>$m=64e(~?U~~VRG@FHip;(21 z0XdORJ}9a*d7Ta)7b4wHHWX75Dap^zNlGlzM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