Merge branch 'master' into Issue-2730_Combined-Ranges

This commit is contained in:
Mark Baker 2022-04-13 18:04:00 +02:00 committed by GitHub
commit 8b83e8ac4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 0 deletions

View File

@ -80,6 +80,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
Nor is this a perfect solution, as there may still be issues when function calls have array arguments that themselves contain function calls; but it's still better than the current logic.
- Fix for escaping double quotes within a formula [Issue #1971](https://github.com/PHPOffice/PhpSpreadsheet/issues/1971) [PR #2651](https://github.com/PHPOffice/PhpSpreadsheet/pull/2651)
- Fix invalid style of cells in empty columns with columnDimensions and rows with rowDimensions in added external sheet. [PR #2739](https://github.com/PHPOffice/PhpSpreadsheet/pull/2739)
## 1.22.0 - 2022-02-18

View File

@ -869,6 +869,19 @@ class Spreadsheet
$cell->setXfIndex($cell->getXfIndex() + $countCellXfs);
}
// update the column dimensions Xfs
foreach ($worksheet->getColumnDimensions() as $columnDimension) {
$columnDimension->setXfIndex($columnDimension->getXfIndex() + $countCellXfs);
}
// update the row dimensions Xfs
foreach ($worksheet->getRowDimensions() as $rowDimension) {
$xfIndex = $rowDimension->getXfIndex();
if ($xfIndex !== null) {
$rowDimension->setXfIndex($xfIndex + $countCellXfs);
}
}
return $this->addSheet($worksheet, $sheetIndex);
}

View File

@ -188,4 +188,62 @@ class SpreadsheetTest extends TestCase
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
$this->object->addExternalSheet($sheet);
}
public function testAddExternalColumnDimensionStyles(): void
{
$spreadsheet1 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
$sheet1->getCell('A1')->setValue(1);
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
$sheet1->getColumnDimension('B')->setWidth(10)->setXfIndex($sheet1->getCell('A1')->getXfIndex());
$index = $sheet1->getColumnDimension('B')->getXfIndex();
self::assertEquals(1, $index);
self::assertCount(2, $spreadsheet1->getCellXfCollection());
$spreadsheet2 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
$sheet2->getCell('A1')->setValue(1);
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
$sheet2->getCell('B2')->getStyle()->getFont()->setSuperscript(true);
$countXfs = count($spreadsheet2->getCellXfCollection());
self::assertEquals(3, $countXfs);
$sheet3 = $spreadsheet2->addExternalSheet($sheet1);
self::assertCount(5, $spreadsheet2->getCellXfCollection());
self::assertTrue($sheet3->getCell('A1')->getStyle()->getFont()->getItalic());
self::assertTrue($sheet3->getCell('B1')->getStyle()->getFont()->getItalic());
self::assertFalse($sheet3->getCell('B1')->getStyle()->getFont()->getBold());
// Prove Xf index changed although style is same.
self::assertEquals($countXfs + $index, $sheet3->getCell('B1')->getXfIndex());
self::assertEquals($countXfs + $index, $sheet3->getColumnDimension('B')->getXfIndex());
}
public function testAddExternalRowDimensionStyles(): void
{
$spreadsheet1 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
$sheet1->getCell('A1')->setValue(1);
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
$sheet1->getRowDimension(2)->setXfIndex($sheet1->getCell('A1')->getXfIndex());
$index = $sheet1->getRowDimension(2)->getXfIndex();
self::assertEquals(1, $index);
self::assertCount(2, $spreadsheet1->getCellXfCollection());
$spreadsheet2 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
$sheet2->getCell('A1')->setValue(1);
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
$sheet2->getCell('B2')->getStyle()->getFont()->setSuperscript(true);
$countXfs = count($spreadsheet2->getCellXfCollection());
self::assertEquals(3, $countXfs);
$sheet3 = $spreadsheet2->addExternalSheet($sheet1);
self::assertCount(5, $spreadsheet2->getCellXfCollection());
self::assertTrue($sheet3->getCell('A1')->getStyle()->getFont()->getItalic());
self::assertTrue($sheet3->getCell('A2')->getStyle()->getFont()->getItalic());
self::assertFalse($sheet3->getCell('A2')->getStyle()->getFont()->getBold());
// Prove Xf index changed although style is same.
self::assertEquals($countXfs + $index, $sheet3->getCell('A2')->getXfIndex());
self::assertEquals($countXfs + $index, $sheet3->getRowDimension(2)->getXfIndex());
}
}