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