Automatic text wrapping due to the presence of new lines in a cell should only be applied if shouldWrapText has not been set on the default style. Indeed the StyleManager does check !$cellStyle->hasSetWrapText() before applying automatic text wrapping, but the following sample shows the opposite behavior:
$defaultStyle = (new StyleBuilder())->setShouldWrapText(false)->build();
$writer = WriterEntityFactory::createXLSXWriter();
$writer->setDefaultRowStyle($defaultStyle)->openToFile('testNoWrap.xlsx');
$writer->addRow(WriterEntityFactory::createRowFromArray(["test\n"]));
$writer->close();
This seems to be because StyleMerger::mergeCellProperties only calls setShouldWrapText on the style to update if the $baseStyle has shouldWrapText true, whereas it probably should call it whenever hasSetWrapText is true.
Current code:
if (!$style->hasSetWrapText() && $baseStyle->shouldWrapText()) {
$styleToUpdate->setShouldWrapText();
}
Possible fix:
if (!$style->hasSetWrapText() && $baseStyle->hasSetWrapText()) {
$styleToUpdate->setShouldWrapText($baseStyle->shouldWrapText());
}
Automatic text wrapping due to the presence of new lines in a cell should only be applied if
shouldWrapText
has not been set on the default style. Indeed theStyleManager
does check!$cellStyle->hasSetWrapText()
before applying automatic text wrapping, but the following sample shows the opposite behavior:This seems to be because
StyleMerger::mergeCellProperties
only callssetShouldWrapText
on the style to update if the$baseStyle
hasshouldWrapText
true, whereas it probably should call it wheneverhasSetWrapText
is true.Current code:
Possible fix: