Merge pull request #2739 from mjan4175/fix-external-sheet-column-styles
Fix invalid styles in empty columns and rows of added external sheet.
This commit is contained in:
commit
4856376024
|
|
@ -79,6 +79,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.
|
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 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
|
## 1.22.0 - 2022-02-18
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -869,6 +869,19 @@ class Spreadsheet
|
||||||
$cell->setXfIndex($cell->getXfIndex() + $countCellXfs);
|
$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);
|
return $this->addSheet($worksheet, $sheetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -188,4 +188,62 @@ class SpreadsheetTest extends TestCase
|
||||||
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
$this->object->addExternalSheet($sheet);
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue