Row objects and Cell styling

This commit introduces Row and Cell entities, that will replace the arrays passed in previously.
It also adds support for Cell styling (instead of Row styling only).
This commit is contained in:
Adrien Loison committed 2017-11-05 02:12:28 +01:00
1 parent fec27e9056
commit 7274226b75
32 files changed
+1113 -859

No files matched your search

+5 -3
View File
@@ -5,6 +5,7 @@ namespace Box\Spout\Writer\ODS;
use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Entity\Sheet;
use Box\Spout\Writer\RowCreationHelper;
use Box\Spout\Writer\WriterFactory;
/**
@@ -13,6 +14,7 @@ use Box\Spout\Writer\WriterFactory;
class SheetTest extends \PHPUnit_Framework_TestCase
{
use TestUsingResource;
use RowCreationHelper;
/**
* @return void
@@ -91,7 +93,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$sheet = $writer->getCurrentSheet();
$sheet->setName($sheetName);
$writer->addRow(['ods--11', 'ods--12']);
$writer->addRow($this->createRowFromValues(['ods--11', 'ods--12']));
$writer->close();
}
@@ -108,9 +110,9 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
$writer->addRow(['ods--sheet1--11', 'ods--sheet1--12']);
$writer->addRow($this->createRowFromValues(['ods--sheet1--11', 'ods--sheet1--12']));
$writer->addNewSheetAndMakeItCurrent();
$writer->addRow(['ods--sheet2--11', 'ods--sheet2--12', 'ods--sheet2--13']);
$writer->addRow($this->createRowFromValues(['ods--sheet2--11', 'ods--sheet2--12', 'ods--sheet2--13']));
$writer->close();
+33 -71
View File
@@ -7,7 +7,9 @@ use Box\Spout\Common\Type;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Helper\ZipHelper;
use Box\Spout\Writer\RowCreationHelper;
use Box\Spout\Writer\WriterFactory;
/**
@@ -16,6 +18,7 @@ use Box\Spout\Writer\WriterFactory;
class WriterTest extends \PHPUnit_Framework_TestCase
{
use TestUsingResource;
use RowCreationHelper;
/**
* @expectedException \Box\Spout\Common\Exception\IOException
@@ -36,7 +39,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldThrowExceptionIfCallAddRowBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::ODS);
$writer->addRow(['ods--11', 'ods--12']);
$writer->addRow($this->createRowFromValues(['ods--11', 'ods--12']));
}
/**
@@ -45,7 +48,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldThrowExceptionIfCalledBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::ODS);
$writer->addRows([['ods--11', 'ods--12']]);
$writer->addRows([$this->createRowFromValues(['ods--11', 'ods--12'])]);
}
/**
@@ -85,7 +88,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
{
$fileName = 'test_add_row_should_throw_exception_if_unsupported_data_type_passed_in.ods';
$dataRows = [
[new \stdClass()],
$this->createRowFromValues([new \stdClass()]),
];
$this->writeToODSFile($dataRows, $fileName);
@@ -98,8 +101,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase
{
$fileName = 'test_add_row_should_cleanup_all_files_if_exception_thrown.ods';
$dataRows = [
['wrong'],
[new \stdClass()],
$this->createRowFromValues(['wrong']),
$this->createRowFromValues([new \stdClass()]),
];
$this->createGeneratedFolderIfNeeded($fileName);
@@ -191,10 +194,10 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldWriteGivenDataToSheet()
{
$fileName = 'test_add_row_should_write_given_data_to_sheet.ods';
$dataRows = [
$dataRows = $this->createRowsFromValues([
['ods--11', 'ods--12'],
['ods--21', 'ods--22', 'ods--23'],
];
]);
$this->writeToODSFile($dataRows, $fileName);
@@ -211,10 +214,10 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldWriteGivenDataToTwoSheets()
{
$fileName = 'test_add_row_should_write_given_data_to_two_sheets.ods';
$dataRows = [
$dataRows = $this->createRowsFromValues([
['ods--11', 'ods--12'],
['ods--21', 'ods--22', 'ods--23'],
];
]);
$numSheets = 2;
$this->writeToMultipleSheetsInODSFile($dataRows, $numSheets, $fileName);
@@ -234,9 +237,9 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldSupportAssociativeArrays()
{
$fileName = 'test_add_row_should_support_associative_arrays.ods';
$dataRows = [
$dataRows = $this->createRowsFromValues([
['foo' => 'ods--11', 'bar' => 'ods--12'],
];
]);
$this->writeToODSFile($dataRows, $fileName);
@@ -253,9 +256,9 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldSupportMultipleTypesOfData()
{
$fileName = 'test_add_row_should_support_multiple_types_of_data.ods';
$dataRows = [
$dataRows = $this->createRowsFromValues([
['ods--11', true, '', 0, 10.2, null],
];
]);
$this->writeToODSFile($dataRows, $fileName);
@@ -290,7 +293,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldUseNumberColumnsRepeatedForRepeatedValues($dataRow, $expectedNumTableCells, $expectedNumColumnsRepeated)
{
$fileName = 'test_add_row_should_use_number_columns_repeated.ods';
$this->writeToODSFile([$dataRow], $fileName);
$this->writeToODSFile($this->createRowsFromValues([$dataRow]), $fileName);
$sheetXmlNode = $this->getSheetXmlNode($fileName, 1);
$tableCellNodes = $sheetXmlNode->getElementsByTagName('table-cell');
@@ -314,18 +317,18 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldWriteGivenDataToTheCorrectSheet()
{
$fileName = 'test_add_row_should_write_given_data_to_the_correct_sheet.ods';
$dataRowsSheet1 = [
$dataRowsSheet1 = $this->createRowsFromValues([
['ods--sheet1--11', 'ods--sheet1--12'],
['ods--sheet1--21', 'ods--sheet1--22', 'ods--sheet1--23'],
];
$dataRowsSheet2 = [
]);
$dataRowsSheet2 = $this->createRowsFromValues([
['ods--sheet2--11', 'ods--sheet2--12'],
['ods--sheet2--21', 'ods--sheet2--22', 'ods--sheet2--23'],
];
$dataRowsSheet1Again = [
]);
$dataRowsSheet1Again = $this->createRowsFromValues([
['ods--sheet1--31', 'ods--sheet1--32'],
['ods--sheet1--41', 'ods--sheet1--42', 'ods--sheet1--43'],
];
]);
$this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName);
@@ -369,11 +372,11 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldAutomaticallyCreateNewSheetsIfMaxRowsReachedAndOptionTurnedOn()
{
$fileName = 'test_add_row_should_automatically_create_new_sheets_if_max_rows_reached_and_option_turned_on.ods';
$dataRows = [
$dataRows = $this->createRowsFromValues([
['ods--sheet1--11', 'ods--sheet1--12'],
['ods--sheet1--21', 'ods--sheet1--22', 'ods--sheet1--23'],
['ods--sheet2--11', 'ods--sheet2--12'], // this should be written in a new sheet
];
]);
// set the maxRowsPerSheet limit to 2
\ReflectionHelper::setStaticValue('\Box\Spout\Writer\ODS\Manager\WorkbookManager', 'maxRowsPerWorksheet', 2);
@@ -393,11 +396,11 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldNotCreateNewSheetsIfMaxRowsReachedAndOptionTurnedOff()
{
$fileName = 'test_add_row_should_not_create_new_sheets_if_max_rows_reached_and_option_turned_off.ods';
$dataRows = [
$dataRows = $this->createRowsFromValues([
['ods--sheet1--11', 'ods--sheet1--12'],
['ods--sheet1--21', 'ods--sheet1--22', 'ods--sheet1--23'],
['ods--sheet1--31', 'ods--sheet1--32'], // this should NOT be written in a new sheet
];
]);
// set the maxRowsPerSheet limit to 2
\ReflectionHelper::setStaticValue('\Box\Spout\Writer\ODS\Manager\WorkbookManager', 'maxRowsPerWorksheet', 2);
@@ -416,9 +419,9 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testAddRowShouldEscapeHtmlSpecialCharacters()
{
$fileName = 'test_add_row_should_escape_html_special_characters.ods';
$dataRows = [
$dataRows = $this->createRowsFromValues([
['I\'m in "great" mood', 'This <must> be escaped & tested'],
];
]);
$this->writeToODSFile($dataRows, $fileName);
@@ -434,7 +437,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$fileName = 'test_add_row_should_keep_new_lines.ods';
$dataRow = ["I have\na dream"];
$this->writeToODSFile([$dataRow], $fileName);
$this->writeToODSFile($this->createRowsFromValues([$dataRow]), $fileName);
$this->assertValueWasWrittenToSheet($fileName, 1, 'I have');
$this->assertValueWasWrittenToSheet($fileName, 1, 'a dream');
@@ -458,55 +461,14 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getGeneratedResourcePath($fileName);
$dataRow = ['foo'];
$this->writeToODSFile([$dataRow], $fileName);
$this->writeToODSFile($this->createRowsFromValues([$dataRow]), $fileName);
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$this->assertEquals('application/vnd.oasis.opendocument.spreadsheet', $finfo->file($resourcePath));
}
/**
* @return void
*/
public function testWriteShouldAcceptCellObjects()
{
$fileName = 'test_writer_should_accept_cell_objects.ods';
$dataRows = [
[new Cell('ods--11'), new Cell('ods--12')],
[new Cell('ods--21'), new Cell('ods--22'), new Cell('ods--23')],
];
$this->writeToODSFile($dataRows, $fileName);
foreach ($dataRows as $dataRow) {
/** @var Cell $cell */
foreach ($dataRow as $cell) {
$this->assertValueWasWritten($fileName, $cell->getValue());
}
}
}
/**
* @return void
*/
public function testWriteShouldAcceptCellObjectsWithDifferentValueTypes()
{
$fileName = 'test_writer_should_accept_cell_objects_with_types.ods';
$dataRows = [
[new Cell('i am a string'), new Cell(51465), new Cell(true), new Cell(51465.5)],
];
$this->writeToODSFile($dataRows, $fileName);
foreach ($dataRows as $dataRow) {
/** @var Cell $cell */
foreach ($dataRow as $cell) {
$this->assertValueWasWritten($fileName, (string) $cell->getValue(), '');
}
}
}
/**
* @param array $allRows
* @param Row[] $allRows
* @param string $fileName
* @param bool $shouldCreateSheetsAutomatically
* @return Writer
@@ -528,7 +490,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
}
/**
* @param array $allRows
* @param Row[] $allRows
* @param int $numSheets
* @param string $fileName
* @param bool $shouldCreateSheetsAutomatically
+55 -121
View File
@@ -7,9 +7,11 @@ use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\Style\BorderBuilder;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\RowCreationHelper;
use Box\Spout\Writer\WriterFactory;
/**
@@ -18,6 +20,7 @@ use Box\Spout\Writer\WriterFactory;
class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
{
use TestUsingResource;
use RowCreationHelper;
/** @var Style */
private $defaultStyle;
@@ -36,7 +39,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldThrowExceptionIfCallAddRowBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::ODS);
$writer->addRowWithStyle(['ods--11', 'ods--12'], $this->defaultStyle);
$writer->addRow($this->createStyledRowFromValues(['ods--11', 'ods--12'], $this->defaultStyle));
}
/**
@@ -45,53 +48,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldThrowExceptionIfCalledBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::ODS);
$writer->addRowWithStyle(['ods--11', 'ods--12'], $this->defaultStyle);
}
/**
* @return array
*/
public function dataProviderForInvalidStyle()
{
return [
['style'],
[new \stdClass()],
[null],
];
}
/**
* @dataProvider dataProviderForInvalidStyle
* @expectedException \Box\Spout\Common\Exception\InvalidArgumentException
*
* @param \Box\Spout\Writer\Common\Entity\Style\Style $style
*/
public function testAddRowWithStyleShouldThrowExceptionIfInvalidStyleGiven($style)
{
$fileName = 'test_add_row_with_style_should_throw_exception.ods';
$this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName);
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
$writer->addRowWithStyle(['ods--11', 'ods--12'], $style);
}
/**
* @dataProvider dataProviderForInvalidStyle
* @expectedException \Box\Spout\Common\Exception\InvalidArgumentException
*
* @param \Box\Spout\Writer\Common\Entity\Style\Style $style
*/
public function testAddRowsWithStyleShouldThrowExceptionIfInvalidStyleGiven($style)
{
$fileName = 'test_add_row_with_style_should_throw_exception.ods';
$this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName);
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
$writer->addRowsWithStyle([['ods--11', 'ods--12']], $style);
$writer->addRow($this->createStyledRowFromValues(['ods--11', 'ods--12'], $this->defaultStyle));
}
/**
@@ -100,10 +57,6 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldListAllUsedStylesInCreatedContentXmlFile()
{
$fileName = 'test_add_row_with_style_should_list_all_used_fonts.ods';
$dataRows = [
['ods--11', 'ods--12'],
['ods--21', 'ods--22'],
];
$style = (new StyleBuilder())
->setFontBold()
@@ -118,7 +71,12 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
->setBackgroundColor(Color::GREEN)
->build();
$this->writeToODSFileWithMultipleStyles($dataRows, $fileName, [$style, $style2]);
$dataRows = [
$this->createRowFromValues(['ods--11', 'ods--12'], $style),
$this->createRowFromValues(['ods--21', 'ods--22'], $style2),
];
$this->writeToODSFile($dataRows, $fileName);
$cellStyleElements = $this->getCellStyleElementsFromContentXmlFile($fileName);
$this->assertEquals(3, count($cellStyleElements), 'There should be 3 separate cell styles, including the default one.');
@@ -144,9 +102,9 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldWriteDefaultStyleSettings()
{
$fileName = 'test_add_row_with_style_should_write_default_style_settings.ods';
$dataRow = ['ods--11', 'ods--12'];
$dataRow = $this->createStyledRowFromValues(['ods--11', 'ods--12'], $this->defaultStyle);
$this->writeToODSFile([$dataRow], $fileName, $this->defaultStyle);
$this->writeToODSFile([$dataRow], $fileName);
$textPropertiesElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'style:text-properties');
$this->assertEquals(Style::DEFAULT_FONT_SIZE . 'pt', $textPropertiesElement->getAttribute('fo:font-size'));
@@ -160,15 +118,16 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldApplyStyleToCells()
{
$fileName = 'test_add_row_with_style_should_apply_style_to_cells.ods';
$dataRows = [
['ods--11'],
['ods--21'],
['ods--31'],
];
$style = (new StyleBuilder())->setFontBold()->build();
$style2 = (new StyleBuilder())->setFontSize(15)->build();
$dataRows = [
$this->createStyledRowFromValues(['ods--11'], $style),
$this->createStyledRowFromValues(['ods--21'], $style2),
$this->createRowFromValues(['ods--31']),
];
$this->writeToODSFileWithMultipleStyles($dataRows, $fileName, [$style, $style2, null]);
$this->writeToODSFile($dataRows, $fileName);
$cellDomElements = $this->getCellElementsFromContentXmlFile($fileName);
$this->assertEquals(3, count($cellDomElements), 'There should be 3 cells with content');
@@ -184,13 +143,14 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldReuseDuplicateStyles()
{
$fileName = 'test_add_row_with_style_should_reuse_duplicate_styles.ods';
$dataRows = [
$style = (new StyleBuilder())->setFontBold()->build();
$dataRows = $this->createStyledRowsFromValues([
['ods--11'],
['ods--21'],
];
$style = (new StyleBuilder())->setFontBold()->build();
], $style);
$this->writeToODSFile($dataRows, $fileName, $style);
$this->writeToODSFile($dataRows, $fileName);
$cellDomElements = $this->getCellElementsFromContentXmlFile($fileName);
$this->assertEquals(2, count($cellDomElements), 'There should be 2 cells with content');
@@ -205,12 +165,13 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldAddWrapTextAlignmentInfoInStylesXmlFileIfSpecified()
{
$fileName = 'test_add_row_with_style_should_add_wrap_text_alignment.ods';
$dataRows = [
['ods--11', 'ods--12'],
];
$style = (new StyleBuilder())->setShouldWrapText()->build();
$this->writeToODSFile($dataRows, $fileName, $style);
$style = (new StyleBuilder())->setShouldWrapText()->build();
$dataRows = $this->createStyledRowsFromValues([
['ods--11', 'ods--12'],
], $style);
$this->writeToODSFile($dataRows, $fileName);
$styleElements = $this->getCellStyleElementsFromContentXmlFile($fileName);
$this->assertEquals(2, count($styleElements), 'There should be 2 styles (default and custom)');
@@ -225,11 +186,11 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldApplyWrapTextIfCellContainsNewLine()
{
$fileName = 'test_add_row_with_style_should_apply_wrap_text_if_new_lines.ods';
$dataRows = [
$dataRows = $this->createStyledRowsFromValues([
["ods--11\nods--11"],
];
], $this->defaultStyle);
$this->writeToODSFile($dataRows, $fileName, $this->defaultStyle);
$this->writeToODSFile($dataRows, $fileName);
$styleElements = $this->getCellStyleElementsFromContentXmlFile($fileName);
$this->assertEquals(2, count($styleElements), 'There should be 2 styles (default and custom)');
@@ -244,12 +205,13 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddBackgroundColor()
{
$fileName = 'test_default_background_style.ods';
$dataRows = [
['defaultBgColor'],
];
$style = (new StyleBuilder())->setBackgroundColor(Color::WHITE)->build();
$this->writeToODSFile($dataRows, $fileName, $style);
$dataRows = $this->createStyledRowsFromValues([
['defaultBgColor'],
], $style);
$this->writeToODSFile($dataRows, $fileName);
$styleElements = $this->getCellStyleElementsFromContentXmlFile($fileName);
$this->assertEquals(2, count($styleElements), 'There should be 2 styles (default and custom)');
@@ -265,12 +227,6 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
{
$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();
@@ -283,7 +239,13 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
(new StyleBuilder())->setBorder($borderTopRedThinDashed)->build(),
];
$this->writeToODSFileWithMultipleStyles($dataRows, $fileName, $styles);
$dataRows = [
$this->createStyledRowFromValues(['row-with-border-bottom-green-thick-solid'], $styles[0]),
$this->createStyledRowFromValues(['row-without-border'], $styles[1]),
$this->createStyledRowFromValues(['row-with-border-top-red-thin-dashed'], $styles[2]),
];
$this->writeToODSFile($dataRows, $fileName);
$styleElements = $this->getCellStyleElementsFromContentXmlFile($fileName);
@@ -328,7 +290,10 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testSetDefaultRowStyle()
{
$fileName = 'test_set_default_row_style.ods';
$dataRows = [['ods--11']];
$dataRows = $this->createRowsFromValues([
['ods--11'],
]);
$defaultFontSize = 50;
$defaultStyle = (new StyleBuilder())->setFontSize($defaultFontSize)->build();
@@ -340,12 +305,11 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
}
/**
* @param array $allRows
* @param Row[] $allRows
* @param string $fileName
* @param \Box\Spout\Writer\Common\Entity\Style\Style $style
* @return Writer
*/
private function writeToODSFile($allRows, $fileName, $style)
private function writeToODSFile($allRows, $fileName)
{
$this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName);
@@ -354,16 +318,16 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
$writer->addRowsWithStyle($allRows, $style);
$writer->addRows($allRows);
$writer->close();
return $writer;
}
/**
* @param array $allRows
* @param Row[] $allRows
* @param string $fileName
* @param \Box\Spout\Writer\Common\Entity\Style\Style|null $defaultStyle
* @param Style $defaultStyle
* @return Writer
*/
private function writeToODSFileWithDefaultStyle($allRows, $fileName, $defaultStyle)
@@ -382,36 +346,6 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
return $writer;
}
/**
* @param array $allRows
* @param string $fileName
* @param \Box\Spout\Writer\Common\Entity\Style\Style|null[] $styles
* @return Writer
*/
private function writeToODSFileWithMultipleStyles($allRows, $fileName, $styles)
{
// there should be as many rows as there are styles passed in
$this->assertEquals(count($allRows), count($styles));
$this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\ODS\Writer $writer */
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
for ($i = 0; $i < count($allRows); $i++) {
if ($styles[$i] === null) {
$writer->addRow($allRows[$i]);
} else {
$writer->addRowWithStyle($allRows[$i], $styles[$i]);
}
}
$writer->close();
return $writer;
}
/**
* @param string $fileName
* @return \DOMNode[]