Fixes #135 Added border support for ODS and XLSX files. Updated README.
This commit is contained in:
1 parent
1891c0b053
commit
e30bc37448
17 files changed
+871
-16
No files matched your search
@@ -5,6 +5,9 @@ namespace Box\Spout\Writer\ODS;
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
use Box\Spout\TestUsingResource;
|
||||
use Box\Spout\Writer\ODS\Helper\BorderHelper;
|
||||
use Box\Spout\Writer\Style\Border;
|
||||
use Box\Spout\Writer\Style\BorderBuilder;
|
||||
use Box\Spout\Writer\Style\Color;
|
||||
use Box\Spout\Writer\Style\Style;
|
||||
use Box\Spout\Writer\Style\StyleBuilder;
|
||||
@@ -208,7 +211,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
|
||||
];
|
||||
$style = (new StyleBuilder())->setShouldWrapText()->build();
|
||||
|
||||
$this->writeToODSFile($dataRows, $fileName,$style);
|
||||
$this->writeToODSFile($dataRows, $fileName, $style);
|
||||
|
||||
$styleElements = $this->getCellStyleElementsFromContentXmlFile($fileName);
|
||||
$this->assertEquals(2, count($styleElements), 'There should be 2 styles (default and custom)');
|
||||
@@ -236,6 +239,72 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFirstChildHasAttributeEquals('wrap', $customStyleElement, 'table-cell-properties', 'fo:wrap-option');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testBorders()
|
||||
{
|
||||
$fileName = 'test_borders.ods';
|
||||
|
||||
$dataRows = [
|
||||
['row-with-border-bottom-green-thick-solid'],
|
||||
['row-without-border'],
|
||||
['row-with-border-top-red-thin-dashed'],
|
||||
];
|
||||
|
||||
$borderBottomGreenThickSolid = (new BorderBuilder())
|
||||
->setBorderBottom(Color::GREEN, Border::WIDTH_THICK, Border::STYLE_SOLID)->build();
|
||||
|
||||
|
||||
$borderTopRedThinDashed = (new BorderBuilder())
|
||||
->setBorderTop(Color::RED, Border::WIDTH_THIN, Border::STYLE_DASHED)->build();
|
||||
|
||||
$styles = [
|
||||
(new StyleBuilder())->setBorder($borderBottomGreenThickSolid)->build(),
|
||||
(new StyleBuilder())->build(),
|
||||
(new StyleBuilder())->setBorder($borderTopRedThinDashed)->build(),
|
||||
];
|
||||
|
||||
$this->writeToODSFileWithMultipleStyles($dataRows, $fileName, $styles);
|
||||
|
||||
$styleElements = $this->getCellStyleElementsFromContentXmlFile($fileName);
|
||||
|
||||
$this->assertEquals(3, count($styleElements), 'There should be 3 styles)');
|
||||
|
||||
// Use reflection for protected members here
|
||||
$widthMap = \ReflectionHelper::getStaticValue('Box\Spout\Writer\ODS\Helper\BorderHelper', 'widthMap');
|
||||
$styleMap = \ReflectionHelper::getStaticValue('Box\Spout\Writer\ODS\Helper\BorderHelper', 'styleMap');
|
||||
|
||||
$expectedFirst = sprintf(
|
||||
'%s %s #%s',
|
||||
$widthMap[Border::WIDTH_THICK],
|
||||
$styleMap[Border::STYLE_SOLID],
|
||||
Color::GREEN
|
||||
);
|
||||
|
||||
$actualFirst = $styleElements[1]
|
||||
->getElementsByTagName('table-cell-properties')
|
||||
->item(0)
|
||||
->getAttribute('fo:border-bottom');
|
||||
|
||||
$this->assertEquals($expectedFirst, $actualFirst);
|
||||
|
||||
$expectedThird = sprintf(
|
||||
'%s %s #%s',
|
||||
$widthMap[Border::WIDTH_THIN],
|
||||
$styleMap[Border::STYLE_DASHED],
|
||||
Color::RED
|
||||
);
|
||||
|
||||
$actualThird = $styleElements[2]
|
||||
->getElementsByTagName('table-cell-properties')
|
||||
->item(0)
|
||||
->getAttribute('fo:border-top');
|
||||
|
||||
$this->assertEquals($expectedThird, $actualThird);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $allRows
|
||||
* @param string $fileName
|
||||
|
||||
Reference in new issue
Block a user