Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Shared;
   4  
   5  use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
   6  
   7  class CodePage
   8  {
   9      /**
  10       * Convert Microsoft Code Page Identifier to Code Page Name which iconv
  11       * and mbstring understands.
  12       *
  13       * @param int $codePage Microsoft Code Page Indentifier
  14       *
  15       * @throws PhpSpreadsheetException
  16       *
  17       * @return string Code Page Name
  18       */
  19      public static function numberToName($codePage)
  20      {
  21          switch ($codePage) {
  22              case 367:
  23                  return 'ASCII'; //    ASCII
  24              case 437:
  25                  return 'CP437'; //    OEM US
  26              case 720:
  27                  throw new PhpSpreadsheetException('Code page 720 not supported.'); //    OEM Arabic
  28              case 737:
  29                  return 'CP737'; //    OEM Greek
  30              case 775:
  31                  return 'CP775'; //    OEM Baltic
  32              case 850:
  33                  return 'CP850'; //    OEM Latin I
  34              case 852:
  35                  return 'CP852'; //    OEM Latin II (Central European)
  36              case 855:
  37                  return 'CP855'; //    OEM Cyrillic
  38              case 857:
  39                  return 'CP857'; //    OEM Turkish
  40              case 858:
  41                  return 'CP858'; //    OEM Multilingual Latin I with Euro
  42              case 860:
  43                  return 'CP860'; //    OEM Portugese
  44              case 861:
  45                  return 'CP861'; //    OEM Icelandic
  46              case 862:
  47                  return 'CP862'; //    OEM Hebrew
  48              case 863:
  49                  return 'CP863'; //    OEM Canadian (French)
  50              case 864:
  51                  return 'CP864'; //    OEM Arabic
  52              case 865:
  53                  return 'CP865'; //    OEM Nordic
  54              case 866:
  55                  return 'CP866'; //    OEM Cyrillic (Russian)
  56              case 869:
  57                  return 'CP869'; //    OEM Greek (Modern)
  58              case 874:
  59                  return 'CP874'; //    ANSI Thai
  60              case 932:
  61                  return 'CP932'; //    ANSI Japanese Shift-JIS
  62              case 936:
  63                  return 'CP936'; //    ANSI Chinese Simplified GBK
  64              case 949:
  65                  return 'CP949'; //    ANSI Korean (Wansung)
  66              case 950:
  67                  return 'CP950'; //    ANSI Chinese Traditional BIG5
  68              case 1200:
  69                  return 'UTF-16LE'; //    UTF-16 (BIFF8)
  70              case 1250:
  71                  return 'CP1250'; //    ANSI Latin II (Central European)
  72              case 1251:
  73                  return 'CP1251'; //    ANSI Cyrillic
  74              case 0:
  75                  //    CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
  76              case 1252:
  77                  return 'CP1252'; //    ANSI Latin I (BIFF4-BIFF7)
  78              case 1253:
  79                  return 'CP1253'; //    ANSI Greek
  80              case 1254:
  81                  return 'CP1254'; //    ANSI Turkish
  82              case 1255:
  83                  return 'CP1255'; //    ANSI Hebrew
  84              case 1256:
  85                  return 'CP1256'; //    ANSI Arabic
  86              case 1257:
  87                  return 'CP1257'; //    ANSI Baltic
  88              case 1258:
  89                  return 'CP1258'; //    ANSI Vietnamese
  90              case 1361:
  91                  return 'CP1361'; //    ANSI Korean (Johab)
  92              case 10000:
  93                  return 'MAC'; //    Apple Roman
  94              case 10001:
  95                  return 'CP932'; //    Macintosh Japanese
  96              case 10002:
  97                  return 'CP950'; //    Macintosh Chinese Traditional
  98              case 10003:
  99                  return 'CP1361'; //    Macintosh Korean
 100              case 10004:
 101                  return 'MACARABIC'; //    Apple Arabic
 102              case 10005:
 103                  return 'MACHEBREW'; //    Apple Hebrew
 104              case 10006:
 105                  return 'MACGREEK'; //    Macintosh Greek
 106              case 10007:
 107                  return 'MACCYRILLIC'; //    Macintosh Cyrillic
 108              case 10008:
 109                  return 'CP936'; //    Macintosh - Simplified Chinese (GB 2312)
 110              case 10010:
 111                  return 'MACROMANIA'; //    Macintosh Romania
 112              case 10017:
 113                  return 'MACUKRAINE'; //    Macintosh Ukraine
 114              case 10021:
 115                  return 'MACTHAI'; //    Macintosh Thai
 116              case 10029:
 117                  return 'MACCENTRALEUROPE'; //    Macintosh Central Europe
 118              case 10079:
 119                  return 'MACICELAND'; //    Macintosh Icelandic
 120              case 10081:
 121                  return 'MACTURKISH'; //    Macintosh Turkish
 122              case 10082:
 123                  return 'MACCROATIAN'; //    Macintosh Croatian
 124              case 21010:
 125                  return 'UTF-16LE'; //    UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
 126              case 32768:
 127                  return 'MAC'; //    Apple Roman
 128              case 32769:
 129                  throw new PhpSpreadsheetException('Code page 32769 not supported.'); //    ANSI Latin I (BIFF2-BIFF3)
 130              case 65000:
 131                  return 'UTF-7'; //    Unicode (UTF-7)
 132              case 65001:
 133                  return 'UTF-8'; //    Unicode (UTF-8)
 134          }
 135  
 136          throw new PhpSpreadsheetException('Unknown codepage: ' . $codePage);
 137      }
 138  }