forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Column Style When Row Dimension Exists Without Style
Fix PHPOffice#3534. For new cells, style is set to Row Dimension Style when Row Dimension exists (even if Row Dimension Style does not exist), else Column Dimension Style when Column Dimension exists. However it should be set to Row Dimension Style when Row Dimension exists *and* Row Dimension Style exists, else ...
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; | ||
|
||
class Issue3534Test extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private static $testbook = 'tests/data/Reader/XLSX/issue.3534.xlsx'; | ||
|
||
public function testReadColumnStyles(): void | ||
{ | ||
$reader = new XlsxReader(); | ||
$spreadsheet = $reader->load(self::$testbook); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
|
||
self::assertSame(['C4'], $sheet->getCellCollection()->getCoordinates(), 'explicitly defined despite no value because colC style conflicts with row4'); | ||
self::assertSame(1, $sheet->getColumnDimension('A')->getXfIndex()); | ||
self::assertNull($sheet->getRowDimension(1)->getXfIndex()); | ||
|
||
$sheet->getCell('A1')->setValue('a1'); | ||
self::assertSame(['C4', 'A1'], $sheet->getCellCollection()->getCoordinates()); | ||
self::assertSame(1, $sheet->getCell('A1')->getXfIndex(), 'no row style so apply column style'); | ||
|
||
$sheet->getCell('A4')->setValue('a4'); | ||
$sheet->getCell('C1')->setValue('c1'); | ||
self::assertSame('ED7D31', $sheet->getStyle('A1')->getFill()->getStartColor()->getRgb(), 'no row style so apply column style'); | ||
self::assertSame('FFC000', $sheet->getStyle('A4')->getFill()->getStartColor()->getRgb(), 'style for row is applied'); | ||
self::assertSame('9DC3E6', $sheet->getStyle('C1')->getFill()->getStartColor()->getRgb(), 'no row style so apply column style'); | ||
self::assertSame('9DC3E6', $sheet->getStyle('C4')->getFill()->getStartColor()->getRgb(), 'style was already set in xml'); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
Binary file not shown.