Apply custom style to empty cells if needed (#307)
Fixes #295 If a row should be written with a custom style, the handling of empty cells should change. Instead of being skipped entirely, empty cells will be applied the custom style, if this style has custom background color or borders. If not, then the cell definition can still be skipped.
This commit is contained in:
1 parent
d4e57b1f0d
commit
3e0afd858f
6 files changed
+110
-15
No files matched your search
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Box\Spout\Writer\XLSX\Helper;
|
||||
|
||||
use Box\Spout\Writer\Style\Border;
|
||||
use Box\Spout\Writer\Style\BorderBuilder;
|
||||
use Box\Spout\Writer\Style\Color;
|
||||
use Box\Spout\Writer\Style\StyleBuilder;
|
||||
|
||||
/**
|
||||
@@ -57,6 +60,27 @@ class StyleHelperTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, $registeredStyle2->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testShouldApplyStyleOnEmptyCell()
|
||||
{
|
||||
$styleWithFont = (new StyleBuilder())->setFontBold()->build();
|
||||
$styleWithBackground = (new StyleBuilder())->setBackgroundColor(Color::BLUE)->build();
|
||||
|
||||
$border = (new BorderBuilder())->setBorderBottom(Color::GREEN)->build();
|
||||
$styleWithBorder = (new StyleBuilder())->setBorder($border)->build();
|
||||
|
||||
$styleHelper = new StyleHelper($this->defaultStyle);
|
||||
$styleHelper->registerStyle($styleWithFont);
|
||||
$styleHelper->registerStyle($styleWithBackground);
|
||||
$styleHelper->registerStyle($styleWithBorder);
|
||||
|
||||
$this->assertFalse($styleHelper->shouldApplyStyleOnEmptyCell($styleWithFont->getId()));
|
||||
$this->assertTrue($styleHelper->shouldApplyStyleOnEmptyCell($styleWithBackground->getId()));
|
||||
$this->assertTrue($styleHelper->shouldApplyStyleOnEmptyCell($styleWithBorder->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user