Skip to content

Commit 1721aa4

Browse files
authored
Merge pull request #4277 from oleibman/biffcover
Slight Increase in Coverage Reading BIFF8
2 parents af07ad1 + c3c1aca commit 1721aa4

File tree

9 files changed

+56
-49
lines changed

9 files changed

+56
-49
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2626
### Fixed
2727

2828
- Add forceFullCalc option to Xlsx Writer. [Issue #4269](https://github.com/PHPOffice/PhpSpreadsheet/issues/4269) [PR #4271](https://github.com/PHPOffice/PhpSpreadsheet/pull/4271)
29-
- More context options may be needed for http(s) image. [Php issue 17121](https://github.com/php/php-src/issues/17121) [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
30-
- Several fixed to ODS Writer. [Issue #4261](https://github.com/PHPOffice/PhpSpreadsheet/issues/4261) [PR #4263](https://github.com/PHPOffice/PhpSpreadsheet/pull/4263) [PR #4264](https://github.com/PHPOffice/PhpSpreadsheet/pull/4264) [PR #4266](https://github.com/PHPOffice/PhpSpreadsheet/pull/4266)
29+
- More context options may be needed for http(s) image. [Php issue 17121](https://github.com/php/php-src/issues/17121) [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
30+
- Coverage-related tweaks to Xls Reader. [PR #4277](https://github.com/PHPOffice/PhpSpreadsheet/pull/4277)
31+
- Several fixed to ODS Writer. [Issue #4261](https://github.com/PHPOffice/PhpSpreadsheet/issues/4261) [PR #4263](https://github.com/PHPOffice/PhpSpreadsheet/pull/4263) [PR #4264](https://github.com/PHPOffice/PhpSpreadsheet/pull/4264) [PR #4266](https://github.com/PHPOffice/PhpSpreadsheet/pull/4266)
3132

3233
## 2024-12-08 - 3.6.0
3334

src/PhpSpreadsheet/Reader/Xls/Color.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ public static function map(int $color, array $palette, int $version): array
2424
return $palette[$color - 8];
2525
}
2626

27-
// default color table
28-
if ($version == Xls::XLS_BIFF8) {
29-
return Color\BIFF8::lookup($color);
30-
}
31-
32-
// BIFF5
33-
return Color\BIFF5::lookup($color);
27+
return ($version === Xls::XLS_BIFF8) ? Color\BIFF8::lookup($color) : Color\BIFF5::lookup($color);
3428
}
3529
}

src/PhpSpreadsheet/Reader/Xls/ConditionalFormatting.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,12 @@ class ConditionalFormatting extends Xls
3636

3737
public static function type(int $type): ?string
3838
{
39-
if (isset(self::$types[$type])) {
40-
return self::$types[$type];
41-
}
42-
43-
return null;
39+
return self::$types[$type] ?? null;
4440
}
4541

4642
public static function operator(int $operator): ?string
4743
{
48-
if (isset(self::$operators[$operator])) {
49-
return self::$operators[$operator];
50-
}
51-
52-
return null;
44+
return self::$operators[$operator] ?? null;
5345
}
5446

5547
/**

src/PhpSpreadsheet/Reader/Xls/DataValidationHelper.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,17 @@ class DataValidationHelper extends Xls
4848

4949
public static function type(int $type): ?string
5050
{
51-
if (isset(self::$types[$type])) {
52-
return self::$types[$type];
53-
}
54-
55-
return null;
51+
return self::$types[$type] ?? null;
5652
}
5753

5854
public static function errorStyle(int $errorStyle): ?string
5955
{
60-
if (isset(self::$errorStyles[$errorStyle])) {
61-
return self::$errorStyles[$errorStyle];
62-
}
63-
64-
return null;
56+
return self::$errorStyles[$errorStyle] ?? null;
6557
}
6658

6759
public static function operator(int $operator): ?string
6860
{
69-
if (isset(self::$operators[$operator])) {
70-
return self::$operators[$operator];
71-
}
72-
73-
return null;
61+
return self::$operators[$operator] ?? null;
7462
}
7563

7664
/**

src/PhpSpreadsheet/Reader/Xls/ListFunctions.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ protected function listWorksheetNames2(string $filename, Xls $xls): array
4444
}
4545

4646
foreach ($xls->sheets as $sheet) {
47-
if ($sheet['sheetType'] != 0x00) {
47+
if ($sheet['sheetType'] === 0x00) {
4848
// 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
49-
continue;
49+
$worksheetNames[] = $sheet['name'];
5050
}
51-
52-
$worksheetNames[] = $sheet['name'];
5351
}
5452

5553
return $worksheetNames;
@@ -93,7 +91,7 @@ protected function listWorksheetInfo2(string $filename, Xls $xls): array
9391

9492
// Parse the individual sheets
9593
foreach ($xls->sheets as $sheet) {
96-
if ($sheet['sheetType'] != 0x00) {
94+
if ($sheet['sheetType'] !== 0x00) {
9795
// 0x00: Worksheet
9896
// 0x02: Chart
9997
// 0x06: Visual Basic module

src/PhpSpreadsheet/Reader/Xls/Style/Border.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ class Border
2828

2929
public static function lookup(int $index): string
3030
{
31-
if (isset(self::$borderStyleMap[$index])) {
32-
return self::$borderStyleMap[$index];
33-
}
34-
35-
return StyleBorder::BORDER_NONE;
31+
return self::$borderStyleMap[$index] ?? StyleBorder::BORDER_NONE;
3632
}
3733
}

src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ class FillPattern
3737
*/
3838
public static function lookup(int $index): string
3939
{
40-
if (isset(self::$fillPatternMap[$index])) {
41-
return self::$fillPatternMap[$index];
42-
}
43-
44-
return Fill::FILL_NONE;
40+
return self::$fillPatternMap[$index] ?? Fill::FILL_NONE;
4541
}
4642
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
4+
5+
use PhpOffice\PhpSpreadsheet\Reader\Xls;
6+
use PhpOffice\PhpSpreadsheet\Shared\Date;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class Biff8CoverTest extends TestCase
10+
{
11+
protected function tearDown(): void
12+
{
13+
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
14+
}
15+
16+
public function testBiff8Coverage(): void
17+
{
18+
$filename = 'tests/data/Reader/XLS/biff8cover.xls';
19+
$reader = new Xls();
20+
$spreadsheet = $reader->load($filename);
21+
$sheet = $spreadsheet->getActiveSheet();
22+
self::assertSame('=SUM({1;2;3;4;5})', $sheet->getCell('A1')->getValue());
23+
self::assertSame(15, $sheet->getCell('A1')->getCalculatedValue());
24+
self::assertSame(
25+
'=VLOOKUP("hello",'
26+
. '{"what",1;"why",TRUE;"hello","there";"when",FALSE}'
27+
. ',2,FALSE)',
28+
$sheet->getCell('C1')->getValue()
29+
);
30+
self::assertSame('there', $sheet->getCell('C1')->getCalculatedValue());
31+
self::assertSame(2, $sheet->getCell('A3')->getValue());
32+
self::assertTrue(
33+
$sheet->getStyle('A3')->getFont()->getSuperscript()
34+
);
35+
self::assertSame('n', $sheet->getCell('B3')->getValue());
36+
self::assertTrue(
37+
$sheet->getStyle('B3')->getFont()->getSubscript()
38+
);
39+
40+
$spreadsheet->disconnectWorksheets();
41+
}
42+
}

tests/data/Reader/XLS/biff8cover.xls

42.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)