Skip to content

Commit

Permalink
Merge pull request #4247 from oleibman/issue4246
Browse files Browse the repository at this point in the history
Swapped Row and Column Indexes in ReferenceHelper
  • Loading branch information
oleibman authored Nov 30, 2024
2 parents a069960 + 1972cb1 commit d9d5ae8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Fixed

- 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)
- Fix minor break handling drawings. [Issue #4241](https://github.com/PHPOffice/PhpSpreadsheet/issues/4241) [PR #4244](https://github.com/PHPOffice/PhpSpreadsheet/pull/4244)
- 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)

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ private function duplicateStylesByRow(Worksheet $worksheet, int $beforeColumn, i
if ($worksheet->cellExists($coordinate)) {
$xfIndex = $worksheet->getCell($coordinate)->getXfIndex();
for ($j = $beforeRow; $j <= $beforeRow - 1 + $numberOfRows; ++$j) {
if (!empty($xfIndex) || $worksheet->cellExists([$j, $i])) {
if (!empty($xfIndex) || $worksheet->cellExists([$i, $j])) {
$worksheet->getCell(Coordinate::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex);
}
}
Expand Down
45 changes: 45 additions & 0 deletions tests/PhpSpreadsheetTests/ReferenceHelper5Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;

class ReferenceHelper5Test extends TestCase
{
public function testIssue4246(): void
{
// code below would have thrown exception because
// row and column were swapped in code
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$row = 987654;
$rowMinus1 = $row - 1;
$rowPlus1 = $row + 1;
$sheet->getCell("A$rowMinus1")->setValue(1);
$sheet->getCell("B$rowMinus1")->setValue(2);
$sheet->getCell("C$rowMinus1")->setValue(3);
$sheet->getStyle("A$rowMinus1")->getFont()->setBold(true);
$sheet->getCell("A$row")->setValue(1);
$sheet->getCell("B$row")->setValue(2);
$sheet->getCell("C$row")->setValue(3);
$sheet->getStyle("B$row")->getFont()->setBold(true);

$sheet->insertNewRowBefore($row);
self::assertTrue(
$sheet->getStyle("A$row")->getFont()->getBold()
);
self::assertFalse(
$sheet->getStyle("B$row")->getFont()->getBold()
);
self::assertFalse(
$sheet->getStyle("A$rowPlus1")->getFont()->getBold()
);
self::assertTrue(
$sheet->getStyle("B$rowPlus1")->getFont()->getBold()
);
$spreadsheet->disconnectWorksheets();
}
}

0 comments on commit d9d5ae8

Please sign in to comment.