chengkun
2025-09-12 26c5c0296e7c094f9a7ae4a4bb3c975796992eaf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
 
namespace PhpOffice\PhpSpreadsheet\Writer\Xls\Style;
 
use PhpOffice\PhpSpreadsheet\Style\Alignment;
 
class CellAlignment
{
    /**
     * @var array<string, int>
     */
    private static array $horizontalMap = [
        Alignment::HORIZONTAL_GENERAL => 0,
        Alignment::HORIZONTAL_LEFT => 1,
        Alignment::HORIZONTAL_RIGHT => 3,
        Alignment::HORIZONTAL_CENTER => 2,
        Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6,
        Alignment::HORIZONTAL_JUSTIFY => 5,
    ];
 
    /**
     * @var array<string, int>
     */
    private static array $verticalMap = [
        Alignment::VERTICAL_BOTTOM => 2,
        Alignment::VERTICAL_TOP => 0,
        Alignment::VERTICAL_CENTER => 1,
        Alignment::VERTICAL_JUSTIFY => 3,
    ];
 
    public static function horizontal(Alignment $alignment): int
    {
        $horizontalAlignment = $alignment->getHorizontal();
 
        if (is_string($horizontalAlignment) && array_key_exists($horizontalAlignment, self::$horizontalMap)) {
            return self::$horizontalMap[$horizontalAlignment];
        }
 
        return self::$horizontalMap[Alignment::HORIZONTAL_GENERAL];
    }
 
    public static function wrap(Alignment $alignment): int
    {
        $wrap = $alignment->getWrapText();
 
        return ($wrap === true) ? 1 : 0;
    }
 
    public static function vertical(Alignment $alignment): int
    {
        $verticalAlignment = $alignment->getVertical();
 
        if (is_string($verticalAlignment) && array_key_exists($verticalAlignment, self::$verticalMap)) {
            return self::$verticalMap[$verticalAlignment];
        }
 
        return self::$verticalMap[Alignment::VERTICAL_BOTTOM];
    }
}