Commit 276c96a 1 parent 80e7317 commit 276c96a Copy full SHA for 276c96a
File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Fastbolt \ExcelWriter \ColumnFormatter ;
4
+
5
+ use Fastbolt \ExcelWriter \ColumnSetting ;
6
+ use PhpOffice \PhpSpreadsheet \Style \Alignment ;
7
+
8
+ class PercentageFormatter extends BaseFormatter
9
+ {
10
+ private int $ decimalLength ;
11
+
12
+ public function __construct (ColumnSetting $ column )
13
+ {
14
+ $ this ->decimalLength = $ column ->getDecimalLength ();
15
+ }
16
+
17
+ public function getAlignment (): array
18
+ {
19
+ return ['horizontal ' => Alignment::HORIZONTAL_RIGHT ];
20
+ }
21
+
22
+ public function getNumberFormat (): array
23
+ {
24
+ $ formatCode = '0. ' . str_repeat ('0 ' , $ this ->decimalLength ) . '% ' ;
25
+
26
+ return ['formatCode ' => $ formatCode ];
27
+ }
28
+ }
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