Blame view

vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xls/Style/CellAlignment.php 1.63 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
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 $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 $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];
      }
  }