|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader\ODS; |
|
4
|
|
|
|
|
5
|
|
|
use Box\Spout\Common\Exception\IOException; |
|
6
|
|
|
use Box\Spout\Reader\AbstractReader; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Reader |
|
10
|
|
|
* This class provides support to read data from a ODS file |
|
11
|
|
|
* |
|
12
|
|
|
* @package Box\Spout\Reader\ODS |
|
13
|
|
|
*/ |
|
14
|
|
|
class Reader extends AbstractReader |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var \ZipArchive */ |
|
17
|
|
|
protected $zip; |
|
18
|
|
|
|
|
19
|
|
|
/** @var SheetIterator To iterator over the ODS sheets */ |
|
20
|
|
|
protected $sheetIterator; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Returns the reader's current options |
|
24
|
|
|
* |
|
25
|
|
|
* @return ReaderOptions |
|
26
|
|
|
*/ |
|
27
|
87 |
|
protected function getOptions() |
|
28
|
|
|
{ |
|
29
|
87 |
|
if (!isset($this->options)) { |
|
30
|
87 |
|
$this->options = new ReaderOptions(); |
|
31
|
87 |
|
} |
|
32
|
87 |
|
return $this->options; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Returns whether stream wrappers are supported |
|
37
|
|
|
* |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
6 |
|
protected function doesSupportStreamWrapper() |
|
41
|
|
|
{ |
|
42
|
6 |
|
return false; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Opens the file at the given file path to make it ready to be read. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $filePath Path of the file to be read |
|
49
|
|
|
* @return void |
|
50
|
|
|
* @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read |
|
51
|
|
|
* @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file |
|
52
|
|
|
*/ |
|
53
|
84 |
|
protected function openReader($filePath) |
|
54
|
3 |
|
{ |
|
55
|
84 |
|
$this->zip = new \ZipArchive(); |
|
56
|
|
|
|
|
57
|
84 |
|
if ($this->zip->open($filePath) === true) { |
|
58
|
84 |
|
$this->sheetIterator = new SheetIterator($filePath, $this->getOptions()); |
|
59
|
84 |
|
} else { |
|
60
|
|
|
throw new IOException("Could not open $filePath for reading."); |
|
61
|
|
|
} |
|
62
|
84 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns an iterator to iterate over sheets. |
|
66
|
|
|
* |
|
67
|
|
|
* @return SheetIterator To iterate over sheets |
|
68
|
|
|
*/ |
|
69
|
84 |
|
protected function getConcreteSheetIterator() |
|
70
|
|
|
{ |
|
71
|
84 |
|
return $this->sheetIterator; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Closes the reader. To be used after reading the file. |
|
76
|
|
|
* |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
75 |
|
protected function closeReader() |
|
80
|
|
|
{ |
|
81
|
75 |
|
if ($this->zip) { |
|
82
|
75 |
|
$this->zip->close(); |
|
83
|
75 |
|
} |
|
84
|
75 |
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|