Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xls Reader Some Ranges Not Handled Properly #4140

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Fixed

- Xls Reader Some Ranges Not Handled Properly. [Issue #1570](https://github.com/PHPOffice/PhpSpreadsheet/issues/1570) [PR #4140](https://github.com/PHPOffice/PhpSpreadsheet/pull/4140)
- Better Handling of legacyDrawing Xml. [Issue #4105](https://github.com/PHPOffice/PhpSpreadsheet/issues/4105) [PR #4122](https://github.com/PHPOffice/PhpSpreadsheet/pull/4122)

## 2024-08-07 - 2.2.2
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -6859,9 +6859,9 @@ private function readBIFF8CellRangeAddressB(string $subData, string $baseCell =
$lc = '$' . $lc;
} else {
// column offset
// offset: 4; size: 2; first column with relative/absolute flags
// offset: 6; size: 2; last column with relative/absolute flags
// bit: 7-0; mask 0x00FF; column index
$relativeLcIndex = 0x00FF & self::getInt2d($subData, 4);
$relativeLcIndex = 0x00FF & self::getInt2d($subData, 6);
$lcIndex = $baseCol + $relativeLcIndex;
$lcIndex = ($lcIndex < 256) ? $lcIndex : $lcIndex - 256;
$lcIndex = ($lcIndex >= 0) ? $lcIndex : $lcIndex + 256;
Expand Down
70 changes: 70 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xls/Pr607Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;

use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Reader\Xls as XlsReader;
use PHPUnit\Framework\TestCase;

class Pr607Test extends TestCase
{
/**
* Test file with cell range expressed in unexpected manner.
*/
public static function testSumData(): void
{
$filename = 'tests/data/Reader/XLS/pr607.sum_data.xls';
$reader = new XlsReader();
$spreadsheet = $reader->load($filename);

$tests = [
'Test' => [
'A1' => 1,
'A2' => 2,
'A3' => 3,
'A4' => 4,
'A5' => 5,
'A6' => 6,
'A7' => 7,
'A8' => 8,
'A9' => 9,
'A10' => 10,

'B1' => 3,
'B2' => 4,
'B3' => 5,
'B4' => 6,
'B5' => 7,
'B6' => 8,
'B7' => 9,
'B8' => 10,
'B9' => 11,
'B10' => 12,

'C1' => 4,
'C2' => 6,
'C3' => 8,
'C4' => 10,
'C5' => 12,
'C6' => 14,
'C7' => 16,
'C8' => 18,
'C9' => 20,
'C10' => 22,
],
];

foreach ($tests as $sheetName => $testsForSheet) {
$sheet = $spreadsheet->getSheetByName($sheetName);
self::assertNotNull($sheet);

foreach ($testsForSheet as $cellCoordinate => $result) {
$calculatedValue = $sheet->getCell($cellCoordinate)->getCalculatedValue();
self::assertSame($result, $calculatedValue, "cell $cellCoordinate");
}
}
$spreadsheet->disconnectWorksheets();
}
}
Binary file added tests/data/Reader/XLS/pr607.sum_data.xls
Binary file not shown.
Loading