CodePage.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * PHPExcel_Shared_CodePage
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Shared
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Shared_CodePage
  28. {
  29. /**
  30. * Convert Microsoft Code Page Identifier to Code Page Name which iconv
  31. * and mbstring understands
  32. *
  33. * @param integer $codePage Microsoft Code Page Indentifier
  34. * @return string Code Page Name
  35. * @throws PHPExcel_Exception
  36. */
  37. public static function NumberToName($codePage = 1252)
  38. {
  39. switch ($codePage) {
  40. case 367:
  41. return 'ASCII'; // ASCII
  42. case 437:
  43. return 'CP437'; // OEM US
  44. case 720:
  45. throw new PHPExcel_Exception('Code page 720 not supported.'); // OEM Arabic
  46. case 737:
  47. return 'CP737'; // OEM Greek
  48. case 775:
  49. return 'CP775'; // OEM Baltic
  50. case 850:
  51. return 'CP850'; // OEM Latin I
  52. case 852:
  53. return 'CP852'; // OEM Latin II (Central European)
  54. case 855:
  55. return 'CP855'; // OEM Cyrillic
  56. case 857:
  57. return 'CP857'; // OEM Turkish
  58. case 858:
  59. return 'CP858'; // OEM Multilingual Latin I with Euro
  60. case 860:
  61. return 'CP860'; // OEM Portugese
  62. case 861:
  63. return 'CP861'; // OEM Icelandic
  64. case 862:
  65. return 'CP862'; // OEM Hebrew
  66. case 863:
  67. return 'CP863'; // OEM Canadian (French)
  68. case 864:
  69. return 'CP864'; // OEM Arabic
  70. case 865:
  71. return 'CP865'; // OEM Nordic
  72. case 866:
  73. return 'CP866'; // OEM Cyrillic (Russian)
  74. case 869:
  75. return 'CP869'; // OEM Greek (Modern)
  76. case 874:
  77. return 'CP874'; // ANSI Thai
  78. case 932:
  79. return 'CP932'; // ANSI Japanese Shift-JIS
  80. case 936:
  81. return 'CP936'; // ANSI Chinese Simplified GBK
  82. case 949:
  83. return 'CP949'; // ANSI Korean (Wansung)
  84. case 950:
  85. return 'CP950'; // ANSI Chinese Traditional BIG5
  86. case 1200:
  87. return 'UTF-16LE'; // UTF-16 (BIFF8)
  88. case 1250:
  89. return 'CP1250'; // ANSI Latin II (Central European)
  90. case 1251:
  91. return 'CP1251'; // ANSI Cyrillic
  92. case 0:
  93. // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
  94. case 1252:
  95. return 'CP1252'; // ANSI Latin I (BIFF4-BIFF7)
  96. case 1253:
  97. return 'CP1253'; // ANSI Greek
  98. case 1254:
  99. return 'CP1254'; // ANSI Turkish
  100. case 1255:
  101. return 'CP1255'; // ANSI Hebrew
  102. case 1256:
  103. return 'CP1256'; // ANSI Arabic
  104. case 1257:
  105. return 'CP1257'; // ANSI Baltic
  106. case 1258:
  107. return 'CP1258'; // ANSI Vietnamese
  108. case 1361:
  109. return 'CP1361'; // ANSI Korean (Johab)
  110. case 10000:
  111. return 'MAC'; // Apple Roman
  112. case 10001:
  113. return 'CP932'; // Macintosh Japanese
  114. case 10002:
  115. return 'CP950'; // Macintosh Chinese Traditional
  116. case 10003:
  117. return 'CP1361'; // Macintosh Korean
  118. case 10004:
  119. return 'MACARABIC'; // Apple Arabic
  120. case 10005:
  121. return 'MACHEBREW'; // Apple Hebrew
  122. case 10006:
  123. return 'MACGREEK'; // Macintosh Greek
  124. case 10007:
  125. return 'MACCYRILLIC'; // Macintosh Cyrillic
  126. case 10008:
  127. return 'CP936'; // Macintosh - Simplified Chinese (GB 2312)
  128. case 10010:
  129. return 'MACROMANIA'; // Macintosh Romania
  130. case 10017:
  131. return 'MACUKRAINE'; // Macintosh Ukraine
  132. case 10021:
  133. return 'MACTHAI'; // Macintosh Thai
  134. case 10029:
  135. return 'MACCENTRALEUROPE'; // Macintosh Central Europe
  136. case 10079:
  137. return 'MACICELAND'; // Macintosh Icelandic
  138. case 10081:
  139. return 'MACTURKISH'; // Macintosh Turkish
  140. case 10082:
  141. return 'MACCROATIAN'; // Macintosh Croatian
  142. case 21010:
  143. return 'UTF-16LE'; // UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
  144. case 32768:
  145. return 'MAC'; // Apple Roman
  146. case 32769:
  147. throw new PHPExcel_Exception('Code page 32769 not supported.'); // ANSI Latin I (BIFF2-BIFF3)
  148. case 65000:
  149. return 'UTF-7'; // Unicode (UTF-7)
  150. case 65001:
  151. return 'UTF-8'; // Unicode (UTF-8)
  152. }
  153. throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
  154. }
  155. }