1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @name: TConfig |
4
|
|
|
* @author: JiaMeng <[email protected]> |
5
|
|
|
* @file: Export.php |
6
|
|
|
* @Date: 2024/03/04 10:15 |
7
|
|
|
*/ |
8
|
|
|
namespace tinymeng\spreadsheet\Util; |
9
|
|
|
|
10
|
|
|
trait TConfig{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* 文件创建者 |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $creator = 'tinymeng'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* 文件名称 |
20
|
|
|
* @var |
21
|
|
|
*/ |
22
|
|
|
private $fileName; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* 文件存储位置 |
26
|
|
|
* @var string|bool |
27
|
|
|
*/ |
28
|
|
|
private $pathName = false; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* 是否居中 |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $horizontalCenter = true; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* 定义表头行高 |
39
|
|
|
* @var int 常用:22 |
40
|
|
|
*/ |
41
|
|
|
private $titleHeight = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* 定义表头列宽(未设置则自动计算宽度) |
45
|
|
|
* @var int 常用:20 |
46
|
|
|
*/ |
47
|
|
|
private $titleWidth = null; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* 定义数据行高 |
51
|
|
|
* @var int 常用:22 |
52
|
|
|
*/ |
53
|
|
|
private $height = null; |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* 自动筛选(是否开启) |
58
|
|
|
* @var bool |
59
|
|
|
*/ |
60
|
|
|
private $autoFilter = false; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* 自动适应文本类型 |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
private $autoDataType = true; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* 冻结窗格(要冻结的首行首列"B2",false不开启) |
70
|
|
|
* @var string|bool |
71
|
|
|
*/ |
72
|
|
|
private $freezePane = false; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* 当前选中sheet |
76
|
|
|
* @var string|bool |
77
|
|
|
*/ |
78
|
|
|
private $sheet = 0; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* 标题占用行数 |
82
|
|
|
* @var int |
83
|
|
|
*/ |
84
|
|
|
private $title_row = 1; |
85
|
|
|
/** |
86
|
|
|
* 报表名称(主标题) |
87
|
|
|
* @var |
88
|
|
|
*/ |
89
|
|
|
private $mainTitle = ''; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* 是否需要报表名称(主标题) |
93
|
|
|
* @var bool |
94
|
|
|
*/ |
95
|
|
|
private $mainTitleLine = false; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool|int|string |
99
|
|
|
*/ |
100
|
|
|
public function getSheet() |
101
|
|
|
{ |
102
|
|
|
return $this->sheet; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param bool|int|string $sheet |
107
|
|
|
*/ |
108
|
|
|
public function setSheet($sheet) |
109
|
|
|
{ |
110
|
|
|
$this->sheet = $sheet; |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function getTitleRow(): int |
116
|
|
|
{ |
117
|
|
|
return $this->title_row; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function setTitleRow(int $title_row) |
121
|
|
|
{ |
122
|
|
|
$this->title_row = $title_row; |
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getCreator(): string |
127
|
|
|
{ |
128
|
|
|
return $this->creator; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function setCreator(string $creator) |
132
|
|
|
{ |
133
|
|
|
$this->creator = $creator; |
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return mixed |
139
|
|
|
*/ |
140
|
|
|
public function getFileName() |
141
|
|
|
{ |
142
|
|
|
return $this->fileName; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param mixed $fileName |
147
|
|
|
*/ |
148
|
|
|
public function setFileName($fileName) |
149
|
|
|
{ |
150
|
|
|
$this->fileName = $fileName; |
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return bool|string |
156
|
|
|
*/ |
157
|
|
|
public function getHorizontalCenter() |
158
|
|
|
{ |
159
|
|
|
return $this->horizontalCenter; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param bool|string $horizontalCenter |
164
|
|
|
*/ |
165
|
|
|
public function setHorizontalCenter($horizontalCenter) |
166
|
|
|
{ |
167
|
|
|
$this->horizontalCenter = $horizontalCenter; |
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function getTitleHeight(): int |
172
|
|
|
{ |
173
|
|
|
return $this->titleHeight; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function setTitleHeight(int $titleHeight) |
177
|
|
|
{ |
178
|
|
|
$this->titleHeight = $titleHeight; |
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function getTitleWidth(): int |
183
|
|
|
{ |
184
|
|
|
return $this->titleWidth; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function setTitleWidth(int $titleWidth) |
188
|
|
|
{ |
189
|
|
|
$this->titleWidth = $titleWidth; |
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function getHeight(): int |
194
|
|
|
{ |
195
|
|
|
return $this->height; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function setHeight(int $height) |
199
|
|
|
{ |
200
|
|
|
$this->height = $height; |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function isAutoFilter(): bool |
205
|
|
|
{ |
206
|
|
|
return $this->autoFilter; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function setAutoFilter(bool $autoFilter) |
210
|
|
|
{ |
211
|
|
|
$this->autoFilter = $autoFilter; |
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function isAutoDataType(): bool |
216
|
|
|
{ |
217
|
|
|
return $this->autoDataType; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function setAutoDataType(bool $autoDataType) |
221
|
|
|
{ |
222
|
|
|
$this->autoDataType = $autoDataType; |
223
|
|
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return bool|string |
228
|
|
|
*/ |
229
|
|
|
public function getFreezePane() |
230
|
|
|
{ |
231
|
|
|
return $this->freezePane; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @param bool|string $freezePane |
236
|
|
|
*/ |
237
|
|
|
public function setFreezePane($freezePane) |
238
|
|
|
{ |
239
|
|
|
$this->freezePane = $freezePane; |
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @param bool|string $pathName |
245
|
|
|
*/ |
246
|
|
|
public function setPathName($pathName) |
247
|
|
|
{ |
248
|
|
|
$this->pathName = $pathName; |
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @param $pathName |
254
|
|
|
* @return bool|mixed|string |
255
|
|
|
*/ |
256
|
|
|
private function getPathName($pathName) |
257
|
|
|
{ |
258
|
|
|
if(!empty($pathName)){ |
259
|
|
|
return $pathName; |
260
|
|
|
} |
261
|
|
|
if($this->pathName){ |
262
|
|
|
return $this->pathName; |
263
|
|
|
} |
264
|
|
|
$pathName = dirname( dirname(dirname(SPREADSHEET_ROOT_PATH))).DIRECTORY_SEPARATOR."public".DIRECTORY_SEPARATOR."export".DIRECTORY_SEPARATOR.date('Ymd').DIRECTORY_SEPARATOR; |
265
|
|
|
return $pathName; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public function isMainTitleLine(): bool |
269
|
|
|
{ |
270
|
|
|
return $this->mainTitleLine; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function setMainTitleLine(bool $mainTitleLine): void |
274
|
|
|
{ |
275
|
|
|
$this->mainTitleLine = $mainTitleLine; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
public function getMainTitle(): string |
279
|
|
|
{ |
280
|
|
|
return $this->mainTitle; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function setMainTitle(string $mainTitle): void |
284
|
|
|
{ |
285
|
|
|
$this->mainTitle = $mainTitle; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
} |
289
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.