Merge remote-tracking branch 'remotes/origin/master' into custom-column-widths
# Conflicts: # src/Spout/Writer/XLSX/Manager/WorksheetManager.php
This commit is contained in:
commit
49e621b822
102 files changed
+1051
-381
No files matched your search
@@ -58,20 +58,50 @@ class StyleRegistryTest extends TestCase
|
||||
$borderRight = (new BorderBuilder())->setBorderRight()->build();
|
||||
|
||||
$styleBorderLeft = (new StyleBuilder())->setBorder($borderLeft)->build();
|
||||
$styleBoderRight = (new StyleBuilder())->setBorder($borderRight)->build();
|
||||
$styleBoderRightBold = (new StyleBuilder())->setBorder($borderRight)->setFontBold()->build();
|
||||
$styleBorderRight = (new StyleBuilder())->setBorder($borderRight)->build();
|
||||
$styleBorderRightBold = (new StyleBuilder())->setBorder($borderRight)->setFontBold()->build();
|
||||
$styleNoBorder = (new StyleBuilder())->setFontItalic()->build();
|
||||
|
||||
$styleRegistry->registerStyle($styleBorderLeft);
|
||||
$styleRegistry->registerStyle($styleBoderRight);
|
||||
$styleRegistry->registerStyle($styleBoderRightBold);
|
||||
$styleRegistry->registerStyle($styleBorderRight);
|
||||
$styleRegistry->registerStyle($styleBorderRightBold);
|
||||
$styleRegistry->registerStyle($styleNoBorder);
|
||||
|
||||
$this->assertCount(2, $styleRegistry->getRegisteredBorders(), 'There should be 2 registered borders');
|
||||
|
||||
$this->assertEquals(1, $styleRegistry->getBorderIdForStyleId($styleBorderLeft->getId()), 'First style with border set should have index 1 (0 is for the default style)');
|
||||
$this->assertEquals(2, $styleRegistry->getBorderIdForStyleId($styleBoderRight->getId()), 'Second style with border set - different from first style - should have index 2');
|
||||
$this->assertEquals(2, $styleRegistry->getBorderIdForStyleId($styleBoderRightBold->getId()), 'Style with border already set should have the same index');
|
||||
$this->assertEquals(2, $styleRegistry->getBorderIdForStyleId($styleBorderRight->getId()), 'Second style with border set - different from first style - should have index 2');
|
||||
$this->assertEquals(2, $styleRegistry->getBorderIdForStyleId($styleBorderRightBold->getId()), 'Style with border already set should have the same index');
|
||||
$this->assertEquals(0, $styleRegistry->getBorderIdForStyleId($styleNoBorder->getId()), 'Style with no border should have index 0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRegisterStyleAlsoRegistersFormats()
|
||||
{
|
||||
$styleRegistry = $this->getStyleRegistry();
|
||||
|
||||
$styleBuiltinFormat = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFormat('0.00')//Builtin format
|
||||
->build();
|
||||
|
||||
$styleUserFormat = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFormat('0.000')
|
||||
->build();
|
||||
$styleNoFormat = (new StyleBuilder())->setFontItalic()->build();
|
||||
|
||||
$styleRegistry->registerStyle($styleBuiltinFormat);
|
||||
$styleRegistry->registerStyle($styleUserFormat);
|
||||
$styleRegistry->registerStyle($styleNoFormat);
|
||||
|
||||
$this->assertCount(2, $styleRegistry->getRegisteredFormats(), 'There should be 2 registered formats');
|
||||
|
||||
$this->assertEquals(2, $styleRegistry->getFormatIdForStyleId($styleBuiltinFormat->getId()), 'First style with builtin format set should have index 2 (0 is for the default style)');
|
||||
$this->assertEquals(164, $styleRegistry->getFormatIdForStyleId($styleUserFormat->getId()), 'Second style with user format set should have index 164 (0 is for the default style)');
|
||||
|
||||
$this->assertEquals(0, $styleRegistry->getFormatIdForStyleId($styleNoFormat->getId()), 'Style with no format should have index 0');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Box\Spout\Writer\XLSX;
|
||||
|
||||
use Box\Spout\Common\Entity\Cell;
|
||||
use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
@@ -375,6 +376,23 @@ class WriterTest extends TestCase
|
||||
$this->assertInlineDataWasWrittenToSheet($fileName, 1, 10.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowShouldSupportCellInError()
|
||||
{
|
||||
$fileName = 'test_add_row_should_support_cell_in_error.xlsx';
|
||||
|
||||
$cell = WriterEntityFactory::createCell('#DIV/0');
|
||||
$cell->setType(Cell::TYPE_ERROR);
|
||||
|
||||
$row = WriterEntityFactory::createRow([$cell]);
|
||||
|
||||
$this->writeToXLSXFile([$row], $fileName);
|
||||
|
||||
$this->assertInlineDataWasWrittenToSheet($fileName, 1, 't="e"><v>#DIV/0</v>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Box\Spout\Writer\XLSX;
|
||||
|
||||
use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Entity\Style\Border;
|
||||
use Box\Spout\Common\Entity\Style\CellAlignment;
|
||||
use Box\Spout\Common\Entity\Style\Color;
|
||||
use Box\Spout\Common\Entity\Style\Style;
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
@@ -210,6 +211,43 @@ class WriterWithStyleTest extends TestCase
|
||||
$this->assertEquals('1', $cellDomElements[1]->getAttribute('s'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowWithNumFmtStyles()
|
||||
{
|
||||
$fileName = 'test_add_row_with_numfmt.xlsx';
|
||||
$style = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFormat('0.00')//Builtin format
|
||||
->build();
|
||||
$style2 = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
->setFormat('0.000')
|
||||
->build();
|
||||
|
||||
$dataRows = [
|
||||
$this->createStyledRowFromValues([1.123456789], $style),
|
||||
$this->createStyledRowFromValues([12.1], $style2),
|
||||
];
|
||||
|
||||
$this->writeToXLSXFile($dataRows, $fileName);
|
||||
|
||||
$formatsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'numFmts');
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$formatsDomElement->getAttribute('count'),
|
||||
'There should be 2 formats, including the default one'
|
||||
);
|
||||
|
||||
$cellXfsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'cellXfs');
|
||||
|
||||
foreach ([2, 164] as $index => $expected) {
|
||||
$xfElement = $cellXfsDomElement->getElementsByTagName('xf')->item($index + 1);
|
||||
$this->assertEquals($expected, $xfElement->getAttribute('numFmtId'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -250,6 +288,24 @@ class WriterWithStyleTest extends TestCase
|
||||
$this->assertFirstChildHasAttributeEquals('1', $xfElement, 'alignment', 'wrapText');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowShouldApplyCellAlignment()
|
||||
{
|
||||
$fileName = 'test_add_row_should_apply_cell_alignment.xlsx';
|
||||
|
||||
$rightAlignedStyle = (new StyleBuilder())->setCellAlignment(CellAlignment::RIGHT)->build();
|
||||
$dataRows = $this->createStyledRowsFromValues([['xlsx--11']], $rightAlignedStyle);
|
||||
|
||||
$this->writeToXLSXFile($dataRows, $fileName);
|
||||
|
||||
$cellXfsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'cellXfs');
|
||||
$xfElement = $cellXfsDomElement->getElementsByTagName('xf')->item(1);
|
||||
$this->assertEquals(1, $xfElement->getAttribute('applyAlignment'));
|
||||
$this->assertFirstChildHasAttributeEquals(CellAlignment::RIGHT, $xfElement, 'alignment', 'horizontal');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user