Pattern Fill style should default to 'solid' if there is a pattern fill with colour but no style (#2050)
* Pattern Fill style should default to 'solid' if there is a pattern fill style for a conditional; though may need to check if there are defined fg/bg colours as well; and only set a fill style if there are defined colurs
This commit is contained in:
parent
cc5c0205d5
commit
d555b5d312
|
|
@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
- Nothing.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Correct default fill style for conditional without a pattern defined [Issue #2035](https://github.com/PHPOffice/PhpSpreadsheet/issues/2035) [PR #2050](https://github.com/PHPOffice/PhpSpreadsheet/pull/2050)
|
||||
- Fixed issue where array key check for existince before accessing arrays in Xlsx.php. [PR #1970](https://github.com/PHPOffice/PhpSpreadsheet/pull/1970)
|
||||
- Fixed issue with quoted strings in number format mask rendered with toFormattedString() [Issue 1972#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1972) [PR #1978](https://github.com/PHPOffice/PhpSpreadsheet/pull/1978)
|
||||
- Fixed issue with percentage formats in number format mask rendered with toFormattedString() [Issue 1929#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1929) [PR #1928](https://github.com/PHPOffice/PhpSpreadsheet/pull/1928)
|
||||
|
|
|
|||
|
|
@ -103,17 +103,21 @@ class Styles extends BaseParserClass
|
|||
self::readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=1]'))->color)
|
||||
);
|
||||
} elseif ($fillStyleXml->patternFill) {
|
||||
$patternType = (string) $fillStyleXml->patternFill['patternType'] != ''
|
||||
? (string) $fillStyleXml->patternFill['patternType']
|
||||
: Fill::FILL_NONE;
|
||||
|
||||
$fillStyle->setFillType($patternType);
|
||||
$defaultFillStyle = Fill::FILL_NONE;
|
||||
if ($fillStyleXml->patternFill->fgColor) {
|
||||
$fillStyle->getStartColor()->setARGB(self::readColor($fillStyleXml->patternFill->fgColor, true));
|
||||
$defaultFillStyle = Fill::FILL_SOLID;
|
||||
}
|
||||
if ($fillStyleXml->patternFill->bgColor) {
|
||||
$fillStyle->getEndColor()->setARGB(self::readColor($fillStyleXml->patternFill->bgColor, true));
|
||||
$defaultFillStyle = Fill::FILL_SOLID;
|
||||
}
|
||||
|
||||
$patternType = (string) $fillStyleXml->patternFill['patternType'] != ''
|
||||
? (string) $fillStyleXml->patternFill['patternType']
|
||||
: $defaultFillStyle;
|
||||
|
||||
$fillStyle->setFillType($patternType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,16 @@ class ColorMap
|
|||
return self::$colorMap["#{$colorRgb}"];
|
||||
}
|
||||
|
||||
// TODO Try and map RGB value to nearest colour within the define pallette
|
||||
// $red = Color::getRed($colorRgb, false);
|
||||
// $green = Color::getGreen($colorRgb, false);
|
||||
// $blue = Color::getBlue($colorRgb, false);
|
||||
|
||||
// $paletteSpace = 3;
|
||||
// $newColor = ($red * $paletteSpace / 256) * ($paletteSpace * $paletteSpace) +
|
||||
// ($green * $paletteSpace / 256) * $paletteSpace +
|
||||
// ($blue * $paletteSpace / 256);
|
||||
|
||||
return $defaultIndex;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,15 @@ class DefaultFillTest extends TestCase
|
|||
self::assertSame('none', $sheet->getCell('J16')->getStyle()->getFill()->getFillType());
|
||||
self::assertSame('solid', $sheet->getCell('C2')->getStyle()->getFill()->getFillType());
|
||||
}
|
||||
|
||||
public function testDefaultConditionalFill(): void
|
||||
{
|
||||
// default fill pattern for a conditional style where the filltype is not defined
|
||||
$filename = 'tests/data/Reader/XLSX/pr2050cf-fill.xlsx';
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($filename);
|
||||
|
||||
$style = $spreadsheet->getActiveSheet()->getConditionalStyles('A1')[0]->getStyle();
|
||||
self::assertSame('solid', $style->getFill()->getFillType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue