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\Exception as PhpSpreadsheetException;
6
 
7
class SheetView
8
{
9
    // Sheet View types
10
    const SHEETVIEW_NORMAL = 'normal';
11
    const SHEETVIEW_PAGE_LAYOUT = 'pageLayout';
12
    const SHEETVIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview';
13
 
14
    private const SHEET_VIEW_TYPES = [
15
        self::SHEETVIEW_NORMAL,
16
        self::SHEETVIEW_PAGE_LAYOUT,
17
        self::SHEETVIEW_PAGE_BREAK_PREVIEW,
18
    ];
19
 
20
    /**
21
     * ZoomScale.
22
     *
23
     * Valid values range from 10 to 400.
24
     */
25
    private ?int $zoomScale = 100;
26
 
27
    /**
28
     * ZoomScaleNormal.
29
     *
30
     * Valid values range from 10 to 400.
31
     */
32
    private ?int $zoomScaleNormal = 100;
33
 
34
    /**
35
     * ZoomScalePageLayoutView.
36
     *
37
     * Valid values range from 10 to 400.
38
     */
39
    private int $zoomScalePageLayoutView = 100;
40
 
41
    /**
42
     * ZoomScaleSheetLayoutView.
43
     *
44
     * Valid values range from 10 to 400.
45
     */
46
    private int $zoomScaleSheetLayoutView = 100;
47
 
48
    /**
49
     * ShowZeros.
50
     *
51
     * If true, "null" values from a calculation will be shown as "0". This is the default Excel behaviour and can be changed
52
     * with the advanced worksheet option "Show a zero in cells that have zero value"
53
     */
54
    private bool $showZeros = true;
55
 
56
    /**
57
     * View.
58
     *
59
     * Valid values range from 10 to 400.
60
     */
61
    private string $sheetviewType = self::SHEETVIEW_NORMAL;
62
 
63
    /**
64
     * Create a new SheetView.
65
     */
66
    public function __construct()
67
    {
68
    }
69
 
70
    /**
71
     * Get ZoomScale.
72
     */
73
    public function getZoomScale(): ?int
74
    {
75
        return $this->zoomScale;
76
    }
77
 
78
    /**
79
     * Set ZoomScale.
80
     * Valid values range from 10 to 400.
81
     *
82
     * @return $this
83
     */
84
    public function setZoomScale(?int $zoomScale): static
85
    {
86
        // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
87
        // but it is apparently still able to handle any scale >= 1
88
        if ($zoomScale === null || $zoomScale >= 1) {
89
            $this->zoomScale = $zoomScale;
90
        } else {
91
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
92
        }
93
 
94
        return $this;
95
    }
96
 
97
    /**
98
     * Get ZoomScaleNormal.
99
     */
100
    public function getZoomScaleNormal(): ?int
101
    {
102
        return $this->zoomScaleNormal;
103
    }
104
 
105
    /**
106
     * Set ZoomScale.
107
     * Valid values range from 10 to 400.
108
     *
109
     * @return $this
110
     */
111
    public function setZoomScaleNormal(?int $zoomScaleNormal): static
112
    {
113
        if ($zoomScaleNormal === null || $zoomScaleNormal >= 1) {
114
            $this->zoomScaleNormal = $zoomScaleNormal;
115
        } else {
116
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
117
        }
118
 
119
        return $this;
120
    }
121
 
122
    public function getZoomScalePageLayoutView(): int
123
    {
124
        return $this->zoomScalePageLayoutView;
125
    }
126
 
127
    public function setZoomScalePageLayoutView(int $zoomScalePageLayoutView): static
128
    {
129
        if ($zoomScalePageLayoutView >= 1) {
130
            $this->zoomScalePageLayoutView = $zoomScalePageLayoutView;
131
        } else {
132
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
133
        }
134
 
135
        return $this;
136
    }
137
 
138
    public function getZoomScaleSheetLayoutView(): int
139
    {
140
        return $this->zoomScaleSheetLayoutView;
141
    }
142
 
143
    public function setZoomScaleSheetLayoutView(int $zoomScaleSheetLayoutView): static
144
    {
145
        if ($zoomScaleSheetLayoutView >= 1) {
146
            $this->zoomScaleSheetLayoutView = $zoomScaleSheetLayoutView;
147
        } else {
148
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
149
        }
150
 
151
        return $this;
152
    }
153
 
154
    /**
155
     * Set ShowZeroes setting.
156
     */
157
    public function setShowZeros(bool $showZeros): void
158
    {
159
        $this->showZeros = $showZeros;
160
    }
161
 
162
    public function getShowZeros(): bool
163
    {
164
        return $this->showZeros;
165
    }
166
 
167
    /**
168
     * Get View.
169
     */
170
    public function getView(): string
171
    {
172
        return $this->sheetviewType;
173
    }
174
 
175
    /**
176
     * Set View.
177
     *
178
     * Valid values are
179
     *        'normal'            self::SHEETVIEW_NORMAL
180
     *        'pageLayout'        self::SHEETVIEW_PAGE_LAYOUT
181
     *        'pageBreakPreview'  self::SHEETVIEW_PAGE_BREAK_PREVIEW
182
     *
183
     * @return $this
184
     */
185
    public function setView(?string $sheetViewType): static
186
    {
187
        // MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' via the user interface
188
        if ($sheetViewType === null) {
189
            $sheetViewType = self::SHEETVIEW_NORMAL;
190
        }
191
        if (in_array($sheetViewType, self::SHEET_VIEW_TYPES)) {
192
            $this->sheetviewType = $sheetViewType;
193
        } else {
194
            throw new PhpSpreadsheetException('Invalid sheetview layout type.');
195
        }
196
 
197
        return $this;
198
    }
199
}