Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Default style with no text wrap is ignored #829

Open
@fwwarr

Description

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());
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions