This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Xls; |
||
4 | |||
5 | /** |
||
6 | * Class PrintSetup |
||
7 | * Contains print-related functionality for each Worksheet |
||
8 | * |
||
9 | * @package Xls |
||
10 | */ |
||
11 | class PrintSetup |
||
12 | { |
||
13 | const ORIENTATION_PORTRAIT = 1; |
||
14 | const ORIENTATION_LANDSCAPE = 0; |
||
15 | |||
16 | const PAPER_CUSTOM = 0; |
||
17 | const PAPER_US_LETTER = 1; |
||
18 | const PAPER_A3 = 8; |
||
19 | const PAPER_A4 = 9; |
||
20 | const PAPER_A5 = 11; |
||
21 | |||
22 | /** |
||
23 | * The paper size |
||
24 | * |
||
25 | * @var integer |
||
26 | */ |
||
27 | protected $paperSize = self::PAPER_CUSTOM; |
||
28 | |||
29 | /** |
||
30 | * Bit specifying paper orientation (for printing). 0 => landscape, 1 => portrait |
||
31 | * |
||
32 | * @var integer |
||
33 | */ |
||
34 | protected $orientation = self::ORIENTATION_PORTRAIT; |
||
35 | |||
36 | /** |
||
37 | * @var Range |
||
38 | */ |
||
39 | protected $printRepeat; |
||
40 | |||
41 | /** |
||
42 | * @var null|Range |
||
43 | */ |
||
44 | protected $printArea = null; |
||
45 | |||
46 | /** |
||
47 | * @var float |
||
48 | */ |
||
49 | protected $printScale = 100; |
||
50 | |||
51 | /** |
||
52 | * Whether to fit to page when printing or not. |
||
53 | * |
||
54 | * @var bool |
||
55 | */ |
||
56 | protected $fitPage = false; |
||
57 | |||
58 | /** |
||
59 | * Number of pages to fit wide |
||
60 | * |
||
61 | * @var integer |
||
62 | */ |
||
63 | protected $fitWidth = 0; |
||
64 | |||
65 | /** |
||
66 | * Number of pages to fit high |
||
67 | * |
||
68 | * @var integer |
||
69 | */ |
||
70 | protected $fitHeight = 0; |
||
71 | |||
72 | /** |
||
73 | * The page header caption |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $header = ''; |
||
78 | |||
79 | /** |
||
80 | * The page footer caption |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $footer = ''; |
||
85 | |||
86 | /** |
||
87 | * The horizontal centering value for the page |
||
88 | * |
||
89 | * @var bool |
||
90 | */ |
||
91 | protected $hcenter = false; |
||
92 | |||
93 | /** |
||
94 | * The vertical centering value for the page |
||
95 | * |
||
96 | * @var bool |
||
97 | */ |
||
98 | protected $vcenter = false; |
||
99 | |||
100 | /** |
||
101 | * @var Margin |
||
102 | */ |
||
103 | protected $margin; |
||
104 | |||
105 | protected $printRowColHeaders = false; |
||
106 | protected $hbreaks = array(); |
||
107 | protected $vbreaks = array(); |
||
108 | protected $printGridLines = true; |
||
109 | |||
110 | /** |
||
111 | * |
||
112 | */ |
||
113 | public function __construct() |
||
114 | { |
||
115 | $this->margin = new Margin(0.75, 0.75, 1.00, 1.00); |
||
116 | $this->margin->setHead(0.5)->setFoot(0.5); |
||
117 | |||
118 | $this->printRepeat = new Range(null, null); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function isPrintAreaSet() |
||
125 | { |
||
126 | return is_object($this->printArea); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @return null|Range |
||
131 | */ |
||
132 | public function getPrintArea() |
||
133 | { |
||
134 | return $this->printArea; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Set the area of each worksheet that will be printed. |
||
139 | * |
||
140 | * @param integer $firstRow First row of the area to print |
||
141 | * @param integer $firstCol First column of the area to print |
||
142 | * @param integer $lastRow Last row of the area to print |
||
143 | * @param integer $lastCol Last column of the area to print |
||
144 | * |
||
145 | * @return PrintSetup |
||
146 | */ |
||
147 | public function setPrintArea($firstRow, $firstCol, $lastRow, $lastCol) |
||
148 | { |
||
149 | $this->printArea = new Range($firstRow, $firstCol, $lastRow, $lastCol); |
||
150 | |||
151 | return $this; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Set the rows to repeat at the top of each printed page. |
||
156 | * |
||
157 | * @param integer $firstRow First row to repeat |
||
158 | * @param integer $lastRow Last row to repeat. Optional. |
||
159 | * |
||
160 | * @return PrintSetup |
||
161 | */ |
||
162 | View Code Duplication | public function printRepeatRows($firstRow, $lastRow = null) |
|
0 ignored issues
–
show
|
|||
163 | { |
||
164 | if (!isset($lastRow)) { |
||
165 | $lastRow = $firstRow; |
||
166 | } |
||
167 | |||
168 | $this->printRepeat |
||
169 | ->setRowFrom($firstRow) |
||
170 | ->setRowTo($lastRow) |
||
171 | ; |
||
172 | |||
173 | if (is_null($this->printRepeat->getColFrom())) { |
||
174 | $this->printRepeat |
||
175 | ->setColFrom(0) |
||
176 | ->setColTo(Biff8::MAX_COL_IDX) |
||
177 | ; |
||
178 | } |
||
179 | |||
180 | return $this; |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * Set the columns to repeat at the left hand side of each printed page. |
||
185 | * |
||
186 | * @param integer $firstCol First column to repeat |
||
187 | * @param integer $lastCol Last column to repeat. Optional. |
||
188 | * |
||
189 | * @return PrintSetup |
||
190 | */ |
||
191 | View Code Duplication | public function printRepeatColumns($firstCol, $lastCol = null) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
192 | { |
||
193 | if (!isset($lastCol)) { |
||
194 | $lastCol = $firstCol; |
||
195 | } |
||
196 | |||
197 | $this->printRepeat |
||
198 | ->setColFrom($firstCol) |
||
199 | ->setColTo($lastCol) |
||
200 | ; |
||
201 | |||
202 | if (is_null($this->printRepeat->getRowFrom())) { |
||
203 | $this->printRepeat |
||
204 | ->setRowFrom(0) |
||
205 | ->setRowTo(Biff8::MAX_ROW_IDX) |
||
206 | ; |
||
207 | } |
||
208 | |||
209 | return $this; |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @return Range |
||
214 | */ |
||
215 | public function getPrintRepeat() |
||
216 | { |
||
217 | return $this->printRepeat; |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * Set the scale factor for the printed page. |
||
222 | * It turns off the "fit to page" option |
||
223 | * |
||
224 | * @param integer $scale The optional scale factor. Defaults to 100 |
||
225 | * |
||
226 | * @throws \Exception |
||
227 | * @return PrintSetup |
||
228 | */ |
||
229 | public function setPrintScale($scale = 100) |
||
230 | { |
||
231 | // Confine the scale to Excel's range |
||
232 | if ($scale < 10 || $scale > 400) { |
||
233 | throw new \Exception("Print scale $scale outside range: 10 <= scale <= 400"); |
||
234 | } |
||
235 | |||
236 | // Turn off "fit to page" option |
||
237 | $this->fitPage = false; |
||
238 | |||
239 | $this->printScale = floor($scale); |
||
240 | |||
241 | return $this; |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * @return float |
||
246 | */ |
||
247 | public function getPrintScale() |
||
248 | { |
||
249 | return $this->printScale; |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * Set the paper type |
||
254 | * |
||
255 | * @param integer $size The type of paper size to use |
||
256 | * |
||
257 | * @return PrintSetup |
||
258 | */ |
||
259 | public function setPaper($size = self::PAPER_CUSTOM) |
||
260 | { |
||
261 | $this->paperSize = $size; |
||
262 | |||
263 | return $this; |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * Set the page orientation as portrait. |
||
268 | * |
||
269 | * @return PrintSetup |
||
270 | */ |
||
271 | public function setPortrait() |
||
272 | { |
||
273 | $this->orientation = self::ORIENTATION_PORTRAIT; |
||
274 | |||
275 | return $this; |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * Set the page orientation as landscape. |
||
280 | * |
||
281 | * @return PrintSetup |
||
282 | */ |
||
283 | public function setLandscape() |
||
284 | { |
||
285 | $this->orientation = self::ORIENTATION_LANDSCAPE; |
||
286 | |||
287 | return $this; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * @return int |
||
292 | */ |
||
293 | public function getOrientation() |
||
294 | { |
||
295 | return $this->orientation; |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * @return int |
||
300 | */ |
||
301 | public function getPaperSize() |
||
302 | { |
||
303 | return $this->paperSize; |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * @return int |
||
308 | */ |
||
309 | public function getFitWidth() |
||
310 | { |
||
311 | return $this->fitWidth; |
||
312 | } |
||
313 | |||
314 | /** |
||
315 | * @return int |
||
316 | */ |
||
317 | public function getFitHeight() |
||
318 | { |
||
319 | return $this->fitHeight; |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * @return boolean |
||
324 | */ |
||
325 | public function isFitPage() |
||
326 | { |
||
327 | return $this->fitPage; |
||
328 | } |
||
329 | |||
330 | /** |
||
331 | * Set the vertical and horizontal number of pages that will define the maximum area printed. |
||
332 | * It doesn't seem to work with OpenOffice. |
||
333 | * |
||
334 | * @param integer $width Maximun width of printed area in pages |
||
335 | * @param integer $height Maximun heigth of printed area in pages |
||
336 | * |
||
337 | * @return PrintSetup |
||
338 | */ |
||
339 | public function fitToPages($width, $height) |
||
340 | { |
||
341 | $this->fitPage = true; |
||
342 | $this->fitWidth = $width; |
||
343 | $this->fitHeight = $height; |
||
344 | |||
345 | return $this; |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * Set the page header caption and optional margin. |
||
350 | * |
||
351 | * @param string $string The header text |
||
352 | * @param float $margin optional head margin in inches. |
||
353 | * |
||
354 | * @return PrintSetup |
||
355 | */ |
||
356 | public function setHeader($string, $margin = 0.50) |
||
357 | { |
||
358 | $this->header = $this->truncateStringIfNeeded($string); |
||
359 | $this->margin->setHead($margin); |
||
360 | |||
361 | return $this; |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * Set the page footer caption and optional margin. |
||
366 | * |
||
367 | * @param string $string The footer text |
||
368 | * @param float $margin optional foot margin in inches. |
||
369 | * |
||
370 | * @return PrintSetup |
||
371 | */ |
||
372 | public function setFooter($string, $margin = 0.50) |
||
373 | { |
||
374 | $this->footer = $this->truncateStringIfNeeded($string); |
||
375 | $this->margin->setFoot($margin); |
||
376 | |||
377 | return $this; |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * @param $string |
||
382 | * |
||
383 | * @return string |
||
384 | */ |
||
385 | protected function truncateStringIfNeeded($string) |
||
386 | { |
||
387 | if (StringUtils::countCharacters($string) > Biff8::MAX_STR_LENGTH) { |
||
388 | $string = StringUtils::substr($string, 0, Biff8::MAX_STR_LENGTH); |
||
389 | } |
||
390 | |||
391 | return $string; |
||
392 | } |
||
393 | |||
394 | /** |
||
395 | * Center the page horinzontally. |
||
396 | * |
||
397 | * @param bool $enable the optional value for centering. Defaults to 1 (center). |
||
398 | * |
||
399 | * @return PrintSetup |
||
400 | */ |
||
401 | public function centerHorizontally($enable = true) |
||
402 | { |
||
403 | $this->hcenter = $enable; |
||
404 | |||
405 | return $this; |
||
406 | } |
||
407 | |||
408 | /** |
||
409 | * Center the page vertically. |
||
410 | * |
||
411 | * @param bool $enable the optional value for centering. Defaults to 1 (center). |
||
412 | * |
||
413 | * @return PrintSetup |
||
414 | */ |
||
415 | public function centerVertically($enable = true) |
||
416 | { |
||
417 | $this->vcenter = $enable; |
||
418 | |||
419 | return $this; |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * Set the option to print the row and column headers on the printed page. |
||
424 | * |
||
425 | * @param bool $print Whether to print the headers or not. Defaults to 1 (print). |
||
426 | * |
||
427 | * @return PrintSetup |
||
428 | */ |
||
429 | public function printRowColHeaders($print = true) |
||
430 | { |
||
431 | $this->printRowColHeaders = $print; |
||
432 | |||
433 | return $this; |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * Store the horizontal page breaks on a worksheet (for printing). |
||
438 | * The breaks represent the row after which the break is inserted. |
||
439 | * |
||
440 | * @param array $breaks Array containing the horizontal page breaks |
||
441 | * |
||
442 | * @return PrintSetup |
||
443 | */ |
||
444 | public function setHPagebreaks($breaks) |
||
445 | { |
||
446 | foreach ($breaks as $break) { |
||
447 | array_push($this->hbreaks, $break); |
||
448 | } |
||
449 | |||
450 | return $this; |
||
451 | } |
||
452 | |||
453 | /** |
||
454 | * Store the vertical page breaks on a worksheet (for printing). |
||
455 | * The breaks represent the column after which the break is inserted. |
||
456 | * |
||
457 | * @param array $breaks Array containing the vertical page breaks |
||
458 | * |
||
459 | * @return PrintSetup |
||
460 | */ |
||
461 | public function setVPagebreaks($breaks) |
||
462 | { |
||
463 | foreach ($breaks as $break) { |
||
464 | array_push($this->vbreaks, $break); |
||
465 | } |
||
466 | |||
467 | return $this; |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * Set the option to hide gridlines on the printed page. |
||
472 | * |
||
473 | * @param bool $enable |
||
474 | * |
||
475 | * @return PrintSetup |
||
476 | */ |
||
477 | public function printGridlines($enable = true) |
||
478 | { |
||
479 | $this->printGridLines = $enable; |
||
480 | |||
481 | return $this; |
||
482 | } |
||
483 | |||
484 | /** |
||
485 | * @return bool |
||
486 | */ |
||
487 | public function shouldPrintRowColHeaders() |
||
488 | { |
||
489 | return (bool)$this->printRowColHeaders; |
||
490 | } |
||
491 | |||
492 | /** |
||
493 | * @return array |
||
494 | */ |
||
495 | public function getHbreaks() |
||
496 | { |
||
497 | return $this->hbreaks; |
||
498 | } |
||
499 | |||
500 | /** |
||
501 | * @return array |
||
502 | */ |
||
503 | public function getVbreaks() |
||
504 | { |
||
505 | return $this->vbreaks; |
||
506 | } |
||
507 | |||
508 | /** |
||
509 | * @return string |
||
510 | */ |
||
511 | public function getHeader() |
||
512 | { |
||
513 | return $this->header; |
||
514 | } |
||
515 | |||
516 | /** |
||
517 | * @return string |
||
518 | */ |
||
519 | public function getFooter() |
||
520 | { |
||
521 | return $this->footer; |
||
522 | } |
||
523 | |||
524 | /** |
||
525 | * @return bool |
||
526 | */ |
||
527 | public function isHcenteringOn() |
||
528 | { |
||
529 | return (bool)$this->hcenter; |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * @return bool |
||
534 | */ |
||
535 | public function isVcenteringOn() |
||
536 | { |
||
537 | return (bool)$this->vcenter; |
||
538 | } |
||
539 | |||
540 | /** |
||
541 | * @return bool |
||
542 | */ |
||
543 | public function shouldPrintGridLines() |
||
544 | { |
||
545 | return (bool)$this->printGridLines; |
||
546 | } |
||
547 | |||
548 | /** |
||
549 | * @return Margin |
||
550 | */ |
||
551 | public function getMargin() |
||
552 | { |
||
553 | return $this->margin; |
||
554 | } |
||
555 | } |
||
556 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.