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 5f58d457..3171eb6b 100644 Binary files a/tests/data/Reader/Ods/data.ods and b/tests/data/Reader/Ods/data.ods differ