Skip to content

Commit 8aa0012

Browse files
committed
Read Code Page for Xls ListWorksheetInfo/Names for BIFF5
Fix PHPOffice#3671. Xls reader was not processing Code Page as part of functions ListWorksheetInfo/Names, which was causing them to fail for for BIFF5 (and BIFF7); this was not a problem for BIFF8. There were no unit tests for these functions for either BIFF5 or BIFF8. There are now.
1 parent d6e2e24 commit 8aa0012

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

src/PhpSpreadsheet/Reader/Xls.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ public function listWorksheetNames($filename)
498498
$this->readDefault();
499499

500500
break 2;
501+
case self::XLS_TYPE_CODEPAGE:
502+
$this->readCodepage();
503+
504+
break;
501505
default:
502506
$this->readDefault();
503507

@@ -557,6 +561,10 @@ public function listWorksheetInfo($filename)
557561
$this->readDefault();
558562

559563
break 2;
564+
case self::XLS_TYPE_CODEPAGE:
565+
$this->readCodepage();
566+
567+
break;
560568
default:
561569
$this->readDefault();
562570

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
4+
5+
use PhpOffice\PhpSpreadsheet\Reader\Xls;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class InfoNamesTest extends TestCase
9+
{
10+
public function testWorksheetNamesBiff5(): void
11+
{
12+
$filename = 'samples/templates/30templatebiff5.xls';
13+
$reader = new Xls();
14+
$names = $reader->listWorksheetNames($filename);
15+
$expected = ['Invoice', 'Terms and conditions'];
16+
self::assertSame($expected, $names);
17+
}
18+
19+
public function testWorksheetInfoBiff5(): void
20+
{
21+
$filename = 'samples/templates/30templatebiff5.xls';
22+
$reader = new Xls();
23+
$info = $reader->listWorksheetInfo($filename);
24+
$expected = [
25+
[
26+
'worksheetName' => 'Invoice',
27+
'lastColumnLetter' => 'E',
28+
'lastColumnIndex' => 4,
29+
'totalRows' => 19,
30+
'totalColumns' => 5,
31+
],
32+
[
33+
'worksheetName' => 'Terms and conditions',
34+
'lastColumnLetter' => 'B',
35+
'lastColumnIndex' => 1,
36+
'totalRows' => 3,
37+
'totalColumns' => 2,
38+
],
39+
];
40+
self::assertSame($expected, $info);
41+
}
42+
43+
public function testWorksheetNamesBiff8(): void
44+
{
45+
$filename = 'samples/templates/31docproperties.xls';
46+
$reader = new Xls();
47+
$names = $reader->listWorksheetNames($filename);
48+
$expected = ['Worksheet'];
49+
self::assertSame($expected, $names);
50+
}
51+
52+
public function testWorksheetInfoBiff8(): void
53+
{
54+
$filename = 'samples/templates/31docproperties.xls';
55+
$reader = new Xls();
56+
$info = $reader->listWorksheetInfo($filename);
57+
$expected = [
58+
[
59+
'worksheetName' => 'Worksheet',
60+
'lastColumnLetter' => 'B',
61+
'lastColumnIndex' => 1,
62+
'totalRows' => 1,
63+
'totalColumns' => 2,
64+
],
65+
];
66+
self::assertSame($expected, $info);
67+
}
68+
69+
public function testWorksheetNamesBiff8Mac(): void
70+
{
71+
// Non-standard codepage
72+
$filename = 'tests/data/Reader/XLS/maccentraleurope.xls';
73+
$reader = new Xls();
74+
$names = $reader->listWorksheetNames($filename);
75+
$expected = ['Arkusz1'];
76+
self::assertSame($expected, $names);
77+
}
78+
79+
public function testWorksheetInfoBiff8Mac(): void
80+
{
81+
$filename = 'tests/data/Reader/XLS/maccentraleurope.xls';
82+
$reader = new Xls();
83+
$info = $reader->listWorksheetInfo($filename);
84+
$expected = [
85+
[
86+
'worksheetName' => 'Arkusz1',
87+
'lastColumnLetter' => 'P',
88+
'lastColumnIndex' => 15,
89+
'totalRows' => 3,
90+
'totalColumns' => 16,
91+
],
92+
];
93+
self::assertSame($expected, $info);
94+
}
95+
}

0 commit comments

Comments
 (0)