File tree 3 files changed +35
-1
lines changed
3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [ Keep a Changelog] ( https://keepachangelog.com )
6
6
and this project adheres to [ Semantic Versioning] ( https://semver.org ) .
7
7
8
+ ## [ Unreleased]
9
+
10
+ ### Added
11
+
12
+ - Add ability to set codepage explicitly for BIFF5 [ #1018 ] ( https://github.com/PHPOffice/PhpSpreadsheet/issues/1018 )
13
+
8
14
## [ 1.13.0] - 2020-05-31
9
15
10
16
### Added
Original file line number Diff line number Diff line change @@ -439,6 +439,20 @@ public function canRead($pFilename)
439
439
}
440
440
}
441
441
442
+ /**
443
+ * @param string $codepage
444
+ *
445
+ * @throws PhpSpreadsheetException
446
+ */
447
+ public function setCodepage (string $ codepage ): void
448
+ {
449
+ if (!CodePage::validate ($ codepage )) {
450
+ throw new PhpSpreadsheetException ('Unknown codepage: ' . $ codepage );
451
+ }
452
+
453
+ $ this ->codepage = $ codepage ;
454
+ }
455
+
442
456
/**
443
457
* Reads names of the worksheets from a file, without parsing the whole file to a PhpSpreadsheet object.
444
458
*
@@ -640,7 +654,7 @@ public function load($pFilename)
640
654
641
655
// initialize
642
656
$ this ->pos = 0 ;
643
- $ this ->codepage = ' CP1252 ' ;
657
+ $ this ->codepage = $ this -> codepage ?: CodePage:: DEFAULT_CODE_PAGE ;
644
658
$ this ->formats = [];
645
659
$ this ->objFonts = [];
646
660
$ this ->palette = [];
Original file line number Diff line number Diff line change 6
6
7
7
class CodePage
8
8
{
9
+ public const DEFAULT_CODE_PAGE = 'CP1252 ' ;
10
+
9
11
private static $ pageArray = [
10
12
0 => 'CP1252 ' , // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
11
13
367 => 'ASCII ' , // ASCII
@@ -65,13 +67,25 @@ class CodePage
65
67
65001 => 'UTF-8 ' , // Unicode (UTF-8)
66
68
];
67
69
70
+ /**
71
+ * @param string $codePage
72
+ *
73
+ * @return bool
74
+ */
75
+ public static function validate (string $ codePage ): bool
76
+ {
77
+ return (in_array ($ codePage , self ::$ pageArray , true ));
78
+ }
79
+
68
80
/**
69
81
* Convert Microsoft Code Page Identifier to Code Page Name which iconv
70
82
* and mbstring understands.
71
83
*
72
84
* @param int $codePage Microsoft Code Page Indentifier
73
85
*
74
86
* @return string Code Page Name
87
+ *
88
+ * @throws PhpSpreadsheetException
75
89
*/
76
90
public static function numberToName (int $ codePage ): string
77
91
{
You can’t perform that action at this time.
0 commit comments