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