Cell alignment
This PR adds support for cell alignment for XLSX and ODS files.
You can now align the content of the cells this way:
```
use Box\Spout\Common\Entity\Style\CellAlignment;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
$style = (new StyleBuilder())
->setCellAlignment(CellAlignment::RIGHT)
->build();
...
```
Possible cell alignments are: LEFT, RIGHT, CENTER and JUSTIFY.
This commit is contained in:
1 parent
0a0b1f7196
commit
9f4c094fa0
12 files changed
+246
-46
No files matched your search
@@ -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;
|
||||
@@ -287,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