spout icon indicating copy to clipboard operation
spout copied to clipboard

ODS writer does not recognise style changes when calculating repeated columns

Open acoulton opened this issue 4 years ago • 0 comments

The code in WorksheetManager to detect whether a cell is repeated only considers the cell value.

Unfortunately this means a row with repeated values but different styles is not rendered correctly.


$s     = WriterEntityFactory::createODSWriter();
$red   = (new StyleBuilder())->setBackgroundColor('ff0000')->build();
$green = (new StyleBuilder())->setBackgroundColor('00ff00')->build();

$s->openToFile('incorrect-repeat.ods');
$s->addRow(
    WriterEntityFactory::createRow(
        [
            WriterEntityFactory::createCell('X', $red),
            WriterEntityFactory::createCell('X', $red),
            WriterEntityFactory::createCell('X', $green)
        ]
    )
);
$s->addRow(
    WriterEntityFactory::createRow(
        [
            WriterEntityFactory::createCell('X', $red),
            WriterEntityFactory::createCell('X', $red),
            WriterEntityFactory::createCell('Y', $green),
            WriterEntityFactory::createCell('X', $red)
        ]
    )
);
$s->close();

Should produce this - and it does if you use an XLSX writer: image

But it actually produces this: image

Note that C1 should have a green background, but doesn't because it is treated as a repeat of A1/B1.

Unfortunately the "repeated cell" check happens before the style ID is allocated, so I think fixing this would have to involve comparing the cell styles directly?

acoulton avatar Mar 19 '20 22:03 acoulton