File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Copyright © Fastbolt Schraubengroßhandels GmbH.
5
+ * For the full copyright and license information, please view the LICENSE
6
+ * file that was distributed with this source code.
7
+ */
8
+
9
+ namespace Fastbolt \ExcelWriter \ColumnFormatter ;
10
+
11
+ use Fastbolt \ExcelWriter \ColumnSetting ;
12
+ use PhpOffice \PhpSpreadsheet \Style \Alignment ;
13
+
14
+ class PercentageFormatter extends BaseFormatter
15
+ {
16
+ private int $ decimalLength ;
17
+
18
+ public function __construct (ColumnSetting $ column )
19
+ {
20
+ $ this ->decimalLength = $ column ->getDecimalLength ();
21
+ }
22
+
23
+ public function getAlignment (): array
24
+ {
25
+ return ['horizontal ' => Alignment::HORIZONTAL_RIGHT ];
26
+ }
27
+
28
+ public function getNumberFormat (): array
29
+ {
30
+ $ formatCode = '0. ' . str_repeat ('0 ' , $ this ->decimalLength ) . '% ' ;
31
+
32
+ return ['formatCode ' => $ formatCode ];
33
+ }
34
+ }
Original file line number Diff line number Diff line change 12
12
use Fastbolt \ExcelWriter \ColumnFormatter \DateFormatter ;
13
13
use Fastbolt \ExcelWriter \ColumnFormatter \FloatFormatter ;
14
14
use Fastbolt \ExcelWriter \ColumnFormatter \IntegerFormatter ;
15
+ use Fastbolt \ExcelWriter \ColumnFormatter \PercentageFormatter ;
15
16
use Fastbolt \ExcelWriter \ColumnFormatter \StringFormatter ;
16
17
17
18
class ColumnSetting
@@ -20,6 +21,7 @@ class ColumnSetting
20
21
public const FORMAT_FLOAT = 'float ' ;
21
22
public const FORMAT_STRING = 'string ' ;
22
23
public const FORMAT_DATE = 'datetime ' ;
24
+ public const FOMRAT_PERCENTAGE = 'percentage ' ;
23
25
24
26
private string $ format ;
25
27
private string $ name = '' ; //excel-name for the column
@@ -92,6 +94,8 @@ public function getFormatter(): ColumnFormatter
92
94
return new IntegerFormatter ();
93
95
case self ::FORMAT_FLOAT :
94
96
return new FloatFormatter ($ this );
97
+ case self ::FOMRAT_PERCENTAGE :
98
+ return new PercentageFormatter ($ this );
95
99
}
96
100
97
101
return new StringFormatter ();
You can’t perform that action at this time.
0 commit comments