Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Worksheet;
4
 
5
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
6
use PhpOffice\PhpSpreadsheet\Helper\Dimension as CssDimension;
7
 
8
class ColumnDimension extends Dimension
9
{
10
    /**
11
     * Column index.
12
     */
13
    private ?string $columnIndex;
14
 
15
    /**
16
     * Column width.
17
     *
18
     * When this is set to a negative value, the column width should be ignored by IWriter
19
     */
20
    private float $width = -1;
21
 
22
    /**
23
     * Auto size?
24
     */
25
    private bool $autoSize = false;
26
 
27
    /**
28
     * Create a new ColumnDimension.
29
     *
30
     * @param ?string $index Character column index
31
     */
32
    public function __construct(?string $index = 'A')
33
    {
34
        // Initialise values
35
        $this->columnIndex = $index;
36
 
37
        // set dimension as unformatted by default
38
        parent::__construct(0);
39
    }
40
 
41
    /**
42
     * Get column index as string eg: 'A'.
43
     */
44
    public function getColumnIndex(): ?string
45
    {
46
        return $this->columnIndex;
47
    }
48
 
49
    /**
50
     * Set column index as string eg: 'A'.
51
     */
52
    public function setColumnIndex(string $index): self
53
    {
54
        $this->columnIndex = $index;
55
 
56
        return $this;
57
    }
58
 
59
    /**
60
     * Get column index as numeric.
61
     */
62
    public function getColumnNumeric(): int
63
    {
64
        return Coordinate::columnIndexFromString($this->columnIndex ?? '');
65
    }
66
 
67
    /**
68
     * Set column index as numeric.
69
     */
70
    public function setColumnNumeric(int $index): self
71
    {
72
        $this->columnIndex = Coordinate::stringFromColumnIndex($index);
73
 
74
        return $this;
75
    }
76
 
77
    /**
78
     * Get Width.
79
     *
80
     * Each unit of column width is equal to the width of one character in the default font size. A value of -1
81
     *      tells Excel to display this column in its default width.
82
     * By default, this will be the return value; but this method also accepts an optional unit of measure argument
83
     *    and will convert the returned value to the specified UoM..
84
     */
85
    public function getWidth(?string $unitOfMeasure = null): float
86
    {
87
        return ($unitOfMeasure === null || $this->width < 0)
88
            ? $this->width
89
            : (new CssDimension((string) $this->width))->toUnit($unitOfMeasure);
90
    }
91
 
92
    /**
93
     * Set Width.
94
     *
95
     * Each unit of column width is equal to the width of one character in the default font size. A value of -1
96
     *      tells Excel to display this column in its default width.
97
     * By default, this will be the unit of measure for the passed value; but this method also accepts an
98
     *    optional unit of measure argument, and will convert the value from the specified UoM using an
99
     *    approximation method.
100
     *
101
     * @return $this
102
     */
103
    public function setWidth(float $width, ?string $unitOfMeasure = null): static
104
    {
105
        $this->width = ($unitOfMeasure === null || $width < 0)
106
            ? $width
107
            : (new CssDimension("{$width}{$unitOfMeasure}"))->width();
108
 
109
        return $this;
110
    }
111
 
112
    /**
113
     * Get Auto Size.
114
     */
115
    public function getAutoSize(): bool
116
    {
117
        return $this->autoSize;
118
    }
119
 
120
    /**
121
     * Set Auto Size.
122
     *
123
     * @return $this
124
     */
125
    public function setAutoSize(bool $autosizeEnabled): static
126
    {
127
        $this->autoSize = $autosizeEnabled;
128
 
129
        return $this;
130
    }
131
}