1 | <?php |
||
14 | class Sheet |
||
15 | { |
||
16 | const DEFAULT_SHEET_NAME_PREFIX = 'Sheet'; |
||
17 | |||
18 | /** Sheet name should not exceed 31 characters */ |
||
19 | const MAX_LENGTH_SHEET_NAME = 31; |
||
20 | |||
21 | /** @var array Invalid characters that cannot be contained in the sheet name */ |
||
22 | private static $INVALID_CHARACTERS_IN_SHEET_NAME = ['\\', '/', '?', '*', ':', '[', ']']; |
||
23 | |||
24 | /** @var array Associative array [SHEET_INDEX] => [SHEET_NAME] keeping track of sheets' name to enforce uniqueness */ |
||
25 | protected static $SHEETS_NAME_USED = []; |
||
26 | |||
27 | /** @var int Index of the sheet, based on order in the workbook (zero-based) */ |
||
28 | protected $index; |
||
29 | |||
30 | /** @var string Name of the sheet */ |
||
31 | protected $name; |
||
32 | |||
33 | /** @var \Box\Spout\Common\Helper\StringHelper */ |
||
34 | protected $stringHelper; |
||
35 | |||
36 | /** |
||
37 | * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based) |
||
38 | */ |
||
39 | 294 | public function __construct($sheetIndex) |
|
45 | |||
46 | /** |
||
47 | * @api |
||
48 | * @return int Index of the sheet, based on order in the workbook (zero-based) |
||
49 | */ |
||
50 | 213 | public function getIndex() |
|
54 | |||
55 | /** |
||
56 | * @api |
||
57 | * @return string Name of the sheet |
||
58 | */ |
||
59 | 222 | public function getName() |
|
63 | |||
64 | /** |
||
65 | * Sets the name of the sheet. Note that Excel has some restrictions on the name: |
||
66 | * - it should not be blank |
||
67 | * - it should not exceed 31 characters |
||
68 | * - it should not contain these characters: \ / ? * : [ or ] |
||
69 | * - it should be unique |
||
70 | * |
||
71 | * @api |
||
72 | * @param string $name Name of the sheet |
||
73 | * @return Sheet |
||
74 | * @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid. |
||
75 | */ |
||
76 | 294 | public function setName($name) |
|
85 | |||
86 | /** |
||
87 | * Throws an exception if the given sheet's name is not valid. |
||
88 | * @see Sheet::setName for validity rules. |
||
89 | * |
||
90 | * @param string $name |
||
91 | * @return void |
||
92 | * @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid. |
||
93 | */ |
||
94 | 294 | protected function throwIfNameIsInvalid($name) |
|
131 | |||
132 | /** |
||
133 | * Returns whether the given name contains at least one invalid character. |
||
134 | * @see Sheet::$INVALID_CHARACTERS_IN_SHEET_NAME for the full list. |
||
135 | * |
||
136 | * @param string $name |
||
137 | * @return bool TRUE if the name contains invalid characters, FALSE otherwise. |
||
138 | */ |
||
139 | 294 | protected function doesContainInvalidCharacters($name) |
|
143 | |||
144 | /** |
||
145 | * Returns whether the given name starts or ends with a single quote |
||
146 | * |
||
147 | * @param string $name |
||
148 | * @return bool TRUE if the name starts or ends with a single quote, FALSE otherwise. |
||
149 | */ |
||
150 | 294 | protected function doesStartOrEndWithSingleQuote($name) |
|
157 | |||
158 | /** |
||
159 | * Returns whether the given name is unique. |
||
160 | * |
||
161 | * @param string $name |
||
162 | * @return bool TRUE if the name is unique, FALSE otherwise. |
||
163 | */ |
||
164 | 294 | protected function isNameUnique($name) |
|
174 | } |
||
175 |