Added support for cell formats when writing Excel files

This commit is contained in:
Alexander Rakushin authored and Adrien Loison committed 2019-10-01 20:08:54 +00:00
1 parent 16a2f91a22
commit 40aecd7b90
6 files changed
+277 -2

No files matched your search

@@ -210,6 +210,47 @@ 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 1 default ones'
);
$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
*/