|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Manager; |
|
4
|
|
|
|
|
5
|
|
|
trait ManagesCellSize |
|
6
|
|
|
{ |
|
7
|
|
|
/** @var float|null The default column width to use */ |
|
8
|
|
|
private $defaultColumnWidth; |
|
9
|
|
|
|
|
10
|
|
|
/** @var float|null The default row height to use */ |
|
11
|
|
|
private $defaultRowHeight; |
|
12
|
|
|
|
|
13
|
|
|
/** @var array Array of min-max-width arrays */ |
|
14
|
|
|
private $columnWidths = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param float|null $width |
|
18
|
|
|
*/ |
|
19
|
93 |
|
public function setDefaultColumnWidth($width) |
|
20
|
|
|
{ |
|
21
|
93 |
|
$this->defaultColumnWidth = $width; |
|
22
|
93 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param float|null $height |
|
26
|
|
|
*/ |
|
27
|
93 |
|
public function setDefaultRowHeight($height) |
|
28
|
|
|
{ |
|
29
|
93 |
|
$this->defaultRowHeight = $height; |
|
30
|
93 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param float $width |
|
34
|
|
|
* @param array $columns One or more columns with this width |
|
35
|
|
|
*/ |
|
36
|
6 |
|
public function setColumnWidth(float $width, ...$columns) |
|
37
|
|
|
{ |
|
38
|
|
|
// Gather sequences |
|
39
|
6 |
|
$sequence = []; |
|
40
|
6 |
|
foreach ($columns as $i) { |
|
41
|
6 |
|
$sequenceLength = count($sequence); |
|
42
|
6 |
|
if ($sequenceLength > 0) { |
|
43
|
4 |
|
$previousValue = $sequence[$sequenceLength - 1]; |
|
44
|
4 |
|
if ($i !== $previousValue + 1) { |
|
45
|
2 |
|
$this->setColumnWidthForRange($width, $sequence[0], $previousValue); |
|
46
|
2 |
|
$sequence = []; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
6 |
|
$sequence[] = $i; |
|
50
|
|
|
} |
|
51
|
6 |
|
$this->setColumnWidthForRange($width, $sequence[0], $sequence[count($sequence) - 1]); |
|
52
|
6 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param float $width The width to set |
|
56
|
|
|
* @param int $start First column index of the range |
|
57
|
|
|
* @param int $end Last column index of the range |
|
58
|
|
|
*/ |
|
59
|
8 |
|
public function setColumnWidthForRange(float $width, int $start, int $end) |
|
60
|
|
|
{ |
|
61
|
8 |
|
$this->columnWidths[] = [$start, $end, $width]; |
|
62
|
8 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|