Skip to content

Commit d9d5ae8

Browse files
authored
Merge pull request #4247 from oleibman/issue4246
Swapped Row and Column Indexes in ReferenceHelper
2 parents a069960 + 1972cb1 commit d9d5ae8

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2525

2626
### Fixed
2727

28+
- Swapped row and column indexes in ReferenceHelper. [Issue #4246](https://github.com/PHPOffice/PhpSpreadsheet/issues/4246) [PR #4247](https://github.com/PHPOffice/PhpSpreadsheet/pull/4247)
2829
- Fix minor break handling drawings. [Issue #4241](https://github.com/PHPOffice/PhpSpreadsheet/issues/4241) [PR #4244](https://github.com/PHPOffice/PhpSpreadsheet/pull/4244)
2930
- Ignore cell formatting when the format is a single @. [Issue #4242](https://github.com/PHPOffice/PhpSpreadsheet/issues/4242) [PR #4243](https://github.com/PHPOffice/PhpSpreadsheet/pull/4243)
3031

src/PhpSpreadsheet/ReferenceHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ private function duplicateStylesByRow(Worksheet $worksheet, int $beforeColumn, i
12151215
if ($worksheet->cellExists($coordinate)) {
12161216
$xfIndex = $worksheet->getCell($coordinate)->getXfIndex();
12171217
for ($j = $beforeRow; $j <= $beforeRow - 1 + $numberOfRows; ++$j) {
1218-
if (!empty($xfIndex) || $worksheet->cellExists([$j, $i])) {
1218+
if (!empty($xfIndex) || $worksheet->cellExists([$i, $j])) {
12191219
$worksheet->getCell(Coordinate::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex);
12201220
}
12211221
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests;
6+
7+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ReferenceHelper5Test extends TestCase
11+
{
12+
public function testIssue4246(): void
13+
{
14+
// code below would have thrown exception because
15+
// row and column were swapped in code
16+
$spreadsheet = new Spreadsheet();
17+
$sheet = $spreadsheet->getActiveSheet();
18+
$row = 987654;
19+
$rowMinus1 = $row - 1;
20+
$rowPlus1 = $row + 1;
21+
$sheet->getCell("A$rowMinus1")->setValue(1);
22+
$sheet->getCell("B$rowMinus1")->setValue(2);
23+
$sheet->getCell("C$rowMinus1")->setValue(3);
24+
$sheet->getStyle("A$rowMinus1")->getFont()->setBold(true);
25+
$sheet->getCell("A$row")->setValue(1);
26+
$sheet->getCell("B$row")->setValue(2);
27+
$sheet->getCell("C$row")->setValue(3);
28+
$sheet->getStyle("B$row")->getFont()->setBold(true);
29+
30+
$sheet->insertNewRowBefore($row);
31+
self::assertTrue(
32+
$sheet->getStyle("A$row")->getFont()->getBold()
33+
);
34+
self::assertFalse(
35+
$sheet->getStyle("B$row")->getFont()->getBold()
36+
);
37+
self::assertFalse(
38+
$sheet->getStyle("A$rowPlus1")->getFont()->getBold()
39+
);
40+
self::assertTrue(
41+
$sheet->getStyle("B$rowPlus1")->getFont()->getBold()
42+
);
43+
$spreadsheet->disconnectWorksheets();
44+
}
45+
}

0 commit comments

Comments
 (0)