1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Entity; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Worksheet |
7
|
|
|
* Entity describing a Worksheet |
8
|
|
|
* |
9
|
|
|
* @package Box\Spout\Writer\Common\Entity |
10
|
|
|
*/ |
11
|
|
|
class Worksheet |
12
|
|
|
{ |
13
|
|
|
/** @var string Path to the XML file that will contain the sheet data */ |
14
|
|
|
private $filePath; |
15
|
|
|
|
16
|
|
|
/** @var Resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */ |
17
|
|
|
private $filePointer; |
18
|
|
|
|
19
|
|
|
/** @var Sheet The "external" sheet */ |
20
|
|
|
private $externalSheet; |
21
|
|
|
|
22
|
|
|
/** @var int Maximum number of columns among all the written rows */ |
23
|
|
|
private $maxNumColumns; |
24
|
|
|
|
25
|
|
|
/** @var int Index of the last written row */ |
26
|
|
|
private $lastWrittenRowIndex; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Worksheet constructor. |
30
|
|
|
* |
31
|
|
|
* @param string $worksheetFilePath |
32
|
|
|
* @param Sheet $externalSheet |
33
|
|
|
*/ |
34
|
78 |
|
public function __construct($worksheetFilePath, Sheet $externalSheet) |
35
|
|
|
{ |
36
|
78 |
|
$this->filePath = $worksheetFilePath; |
37
|
78 |
|
$this->filePointer = null; |
38
|
78 |
|
$this->externalSheet = $externalSheet; |
39
|
78 |
|
$this->maxNumColumns = 0; |
40
|
78 |
|
$this->lastWrittenRowIndex = 0; |
41
|
78 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
78 |
|
public function getFilePath() |
47
|
|
|
{ |
48
|
78 |
|
return $this->filePath; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return Resource |
53
|
|
|
*/ |
54
|
8 |
|
public function getFilePointer() |
55
|
|
|
{ |
56
|
8 |
|
return $this->filePointer; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Resource $filePointer |
61
|
|
|
*/ |
62
|
78 |
|
public function setFilePointer($filePointer) |
63
|
|
|
{ |
64
|
78 |
|
$this->filePointer = $filePointer; |
65
|
78 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return Sheet |
69
|
|
|
*/ |
70
|
12 |
|
public function getExternalSheet() |
71
|
|
|
{ |
72
|
12 |
|
return $this->externalSheet; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
4 |
|
public function getMaxNumColumns() |
79
|
|
|
{ |
80
|
4 |
|
return $this->maxNumColumns; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param int $maxNumColumns |
85
|
|
|
*/ |
86
|
|
|
public function setMaxNumColumns($maxNumColumns) |
87
|
|
|
{ |
88
|
|
|
$this->maxNumColumns = $maxNumColumns; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return int |
93
|
|
|
*/ |
94
|
|
|
public function getLastWrittenRowIndex() |
95
|
|
|
{ |
96
|
|
|
return $this->lastWrittenRowIndex; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param int $lastWrittenRowIndex |
101
|
|
|
*/ |
102
|
|
|
public function setLastWrittenRowIndex($lastWrittenRowIndex) |
103
|
|
|
{ |
104
|
|
|
$this->lastWrittenRowIndex = $lastWrittenRowIndex; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return int The ID of the worksheet |
109
|
|
|
*/ |
110
|
4 |
|
public function getId() |
111
|
|
|
{ |
112
|
|
|
// sheet index is zero-based, while ID is 1-based |
113
|
4 |
|
return $this->externalSheet->getIndex() + 1; |
114
|
|
|
} |
115
|
|
|
} |