|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\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\Common\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
|
|
|
* @return Resource |
|
55
|
|
|
*/ |
|
56
|
70 |
|
public function getFilePointer() |
|
57
|
|
|
{ |
|
58
|
70 |
|
return $this->filePointer; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param Resource $filePointer |
|
63
|
|
|
*/ |
|
64
|
89 |
|
public function setFilePointer($filePointer) |
|
65
|
|
|
{ |
|
66
|
89 |
|
$this->filePointer = $filePointer; |
|
67
|
89 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return Sheet |
|
71
|
|
|
*/ |
|
72
|
72 |
|
public function getExternalSheet() |
|
73
|
|
|
{ |
|
74
|
72 |
|
return $this->externalSheet; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return int |
|
79
|
|
|
*/ |
|
80
|
65 |
|
public function getMaxNumColumns() |
|
81
|
|
|
{ |
|
82
|
65 |
|
return $this->maxNumColumns; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param int $maxNumColumns |
|
87
|
|
|
*/ |
|
88
|
61 |
|
public function setMaxNumColumns($maxNumColumns) |
|
89
|
|
|
{ |
|
90
|
61 |
|
$this->maxNumColumns = $maxNumColumns; |
|
91
|
61 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return int |
|
95
|
|
|
*/ |
|
96
|
64 |
|
public function getLastWrittenRowIndex() |
|
97
|
|
|
{ |
|
98
|
64 |
|
return $this->lastWrittenRowIndex; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param int $lastWrittenRowIndex |
|
103
|
|
|
*/ |
|
104
|
61 |
|
public function setLastWrittenRowIndex($lastWrittenRowIndex) |
|
105
|
|
|
{ |
|
106
|
61 |
|
$this->lastWrittenRowIndex = $lastWrittenRowIndex; |
|
107
|
61 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return int The ID of the worksheet |
|
111
|
|
|
*/ |
|
112
|
36 |
|
public function getId() |
|
113
|
|
|
{ |
|
114
|
|
|
// sheet index is zero-based, while ID is 1-based |
|
115
|
36 |
|
return $this->externalSheet->getIndex() + 1; |
|
116
|
|
|
} |
|
117
|
|
|
} |