1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Entity; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Writer\Common\Manager\SheetManager; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Sheet |
9
|
|
|
* External representation of a worksheet |
10
|
|
|
*/ |
11
|
|
|
class Sheet |
12
|
|
|
{ |
13
|
|
|
const DEFAULT_SHEET_NAME_PREFIX = 'Sheet'; |
14
|
|
|
|
15
|
|
|
/** @var int Index of the sheet, based on order in the workbook (zero-based) */ |
16
|
|
|
private $index; |
17
|
|
|
|
18
|
|
|
/** @var string ID of the sheet's associated workbook. Used to restrict sheet name uniqueness enforcement to a single workbook */ |
19
|
|
|
private $associatedWorkbookId; |
20
|
|
|
|
21
|
|
|
/** @var string Name of the sheet */ |
22
|
|
|
private $name; |
23
|
|
|
|
24
|
|
|
/** @var bool Visibility of the sheet */ |
25
|
|
|
private $isVisible; |
26
|
|
|
|
27
|
|
|
/** @var SheetManager Sheet manager */ |
28
|
|
|
private $sheetManager; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based) |
32
|
|
|
* @param string $associatedWorkbookId ID of the sheet's associated workbook |
33
|
|
|
* @param SheetManager $sheetManager To manage sheets |
34
|
|
|
*/ |
35
|
95 |
|
public function __construct($sheetIndex, $associatedWorkbookId, SheetManager $sheetManager) |
36
|
|
|
{ |
37
|
95 |
|
$this->index = $sheetIndex; |
38
|
95 |
|
$this->associatedWorkbookId = $associatedWorkbookId; |
39
|
|
|
|
40
|
95 |
|
$this->sheetManager = $sheetManager; |
41
|
95 |
|
$this->sheetManager->markWorkbookIdAsUsed($associatedWorkbookId); |
42
|
|
|
|
43
|
95 |
|
$this->setName(self::DEFAULT_SHEET_NAME_PREFIX . ($sheetIndex + 1)); |
44
|
95 |
|
$this->setIsVisible(true); |
45
|
95 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return int Index of the sheet, based on order in the workbook (zero-based) |
49
|
|
|
*/ |
50
|
95 |
|
public function getIndex() |
51
|
|
|
{ |
52
|
95 |
|
return $this->index; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
95 |
|
public function getAssociatedWorkbookId() |
59
|
|
|
{ |
60
|
95 |
|
return $this->associatedWorkbookId; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string Name of the sheet |
65
|
|
|
*/ |
66
|
95 |
|
public function getName() |
67
|
|
|
{ |
68
|
95 |
|
return $this->name; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Sets the name of the sheet. Note that Excel has some restrictions on the name: |
73
|
|
|
* - it should not be blank |
74
|
|
|
* - it should not exceed 31 characters |
75
|
|
|
* - it should not contain these characters: \ / ? * : [ or ] |
76
|
|
|
* - it should be unique |
77
|
|
|
* |
78
|
|
|
* @param string $name Name of the sheet |
79
|
|
|
* @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid. |
80
|
|
|
* @return Sheet |
81
|
|
|
*/ |
82
|
95 |
|
public function setName($name) |
83
|
|
|
{ |
84
|
95 |
|
$this->sheetManager->throwIfNameIsInvalid($name, $this); |
85
|
|
|
|
86
|
95 |
|
$this->name = $name; |
87
|
|
|
|
88
|
95 |
|
$this->sheetManager->markSheetNameAsUsed($this); |
89
|
|
|
|
90
|
95 |
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return bool isVisible Visibility of the sheet |
95
|
|
|
*/ |
96
|
70 |
|
public function isVisible() |
97
|
|
|
{ |
98
|
70 |
|
return $this->isVisible; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param bool $isVisible Visibility of the sheet |
103
|
|
|
* @return Sheet |
104
|
|
|
*/ |
105
|
95 |
|
public function setIsVisible($isVisible) |
106
|
|
|
{ |
107
|
95 |
|
$this->isVisible = $isVisible; |
108
|
|
|
|
109
|
95 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|