Skip to content

Commit

Permalink
Merge pull request #4277 from oleibman/biffcover
Browse files Browse the repository at this point in the history
Slight Increase in Coverage Reading BIFF8
  • Loading branch information
oleibman authored Dec 23, 2024
2 parents af07ad1 + c3c1aca commit 1721aa4
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 49 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed

- Add forceFullCalc option to Xlsx Writer. [Issue #4269](https://github.com/PHPOffice/PhpSpreadsheet/issues/4269) [PR #4271](https://github.com/PHPOffice/PhpSpreadsheet/pull/4271)
- 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)
- 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)
- 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)
- Coverage-related tweaks to Xls Reader. [PR #4277](https://github.com/PHPOffice/PhpSpreadsheet/pull/4277)
- 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)

## 2024-12-08 - 3.6.0

Expand Down
8 changes: 1 addition & 7 deletions src/PhpSpreadsheet/Reader/Xls/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ public static function map(int $color, array $palette, int $version): array
return $palette[$color - 8];
}

// default color table
if ($version == Xls::XLS_BIFF8) {
return Color\BIFF8::lookup($color);
}

// BIFF5
return Color\BIFF5::lookup($color);
return ($version === Xls::XLS_BIFF8) ? Color\BIFF8::lookup($color) : Color\BIFF5::lookup($color);
}
}
12 changes: 2 additions & 10 deletions src/PhpSpreadsheet/Reader/Xls/ConditionalFormatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,12 @@ class ConditionalFormatting extends Xls

public static function type(int $type): ?string
{
if (isset(self::$types[$type])) {
return self::$types[$type];
}

return null;
return self::$types[$type] ?? null;
}

public static function operator(int $operator): ?string
{
if (isset(self::$operators[$operator])) {
return self::$operators[$operator];
}

return null;
return self::$operators[$operator] ?? null;
}

/**
Expand Down
18 changes: 3 additions & 15 deletions src/PhpSpreadsheet/Reader/Xls/DataValidationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,17 @@ class DataValidationHelper extends Xls

public static function type(int $type): ?string
{
if (isset(self::$types[$type])) {
return self::$types[$type];
}

return null;
return self::$types[$type] ?? null;
}

public static function errorStyle(int $errorStyle): ?string
{
if (isset(self::$errorStyles[$errorStyle])) {
return self::$errorStyles[$errorStyle];
}

return null;
return self::$errorStyles[$errorStyle] ?? null;
}

public static function operator(int $operator): ?string
{
if (isset(self::$operators[$operator])) {
return self::$operators[$operator];
}

return null;
return self::$operators[$operator] ?? null;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/PhpSpreadsheet/Reader/Xls/ListFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ protected function listWorksheetNames2(string $filename, Xls $xls): array
}

foreach ($xls->sheets as $sheet) {
if ($sheet['sheetType'] != 0x00) {
if ($sheet['sheetType'] === 0x00) {
// 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
continue;
$worksheetNames[] = $sheet['name'];
}

$worksheetNames[] = $sheet['name'];
}

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

// Parse the individual sheets
foreach ($xls->sheets as $sheet) {
if ($sheet['sheetType'] != 0x00) {
if ($sheet['sheetType'] !== 0x00) {
// 0x00: Worksheet
// 0x02: Chart
// 0x06: Visual Basic module
Expand Down
6 changes: 1 addition & 5 deletions src/PhpSpreadsheet/Reader/Xls/Style/Border.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class Border

public static function lookup(int $index): string
{
if (isset(self::$borderStyleMap[$index])) {
return self::$borderStyleMap[$index];
}

return StyleBorder::BORDER_NONE;
return self::$borderStyleMap[$index] ?? StyleBorder::BORDER_NONE;
}
}
6 changes: 1 addition & 5 deletions src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class FillPattern
*/
public static function lookup(int $index): string
{
if (isset(self::$fillPatternMap[$index])) {
return self::$fillPatternMap[$index];
}

return Fill::FILL_NONE;
return self::$fillPatternMap[$index] ?? Fill::FILL_NONE;
}
}
42 changes: 42 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xls/Biff8CoverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;

use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;

class Biff8CoverTest extends TestCase
{
protected function tearDown(): void
{
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}

public function testBiff8Coverage(): void
{
$filename = 'tests/data/Reader/XLS/biff8cover.xls';
$reader = new Xls();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('=SUM({1;2;3;4;5})', $sheet->getCell('A1')->getValue());
self::assertSame(15, $sheet->getCell('A1')->getCalculatedValue());
self::assertSame(
'=VLOOKUP("hello",'
. '{"what",1;"why",TRUE;"hello","there";"when",FALSE}'
. ',2,FALSE)',
$sheet->getCell('C1')->getValue()
);
self::assertSame('there', $sheet->getCell('C1')->getCalculatedValue());
self::assertSame(2, $sheet->getCell('A3')->getValue());
self::assertTrue(
$sheet->getStyle('A3')->getFont()->getSuperscript()
);
self::assertSame('n', $sheet->getCell('B3')->getValue());
self::assertTrue(
$sheet->getStyle('B3')->getFont()->getSubscript()
);

$spreadsheet->disconnectWorksheets();
}
}
Binary file added tests/data/Reader/XLS/biff8cover.xls
Binary file not shown.

0 comments on commit 1721aa4

Please sign in to comment.