Add soft newline support for XLSX exports
XLSX cells now properly display newlines when content contains \n characters. Previously, using | join("\n") would create separate rows instead of line breaks within a single cell.
Changes
-
BeamModel: Added
wrapTextproperty (defaults totrue) andsetWrapText()method -
BeamService: Apply
wrap_textstyle to XLSX rows to enable proper newline rendering - Documentation: Added examples for soft newlines including array joins
Usage
{# Basic multi-line cells #}
{% set beam = craft.beam.create({
header: ['Name', 'Address'],
content: [
['John Doe', "123 Main St\nApt 4B\nNew York, NY"]
]
}) %}
{# Join arrays with newlines (original issue) #}
{% set items = ['Item 1', 'Item 2', 'Item 3'] %}
{% do beam.append(['Order', items|join("\n")]) %}
{% do beam.xlsx() %}
{# Disable if needed #}
{% do beam.setWrapText(false) %}
The underlying php_xlsxwriter library already preserved \n characters in XML, but Excel requires the wrapText="true" cell style attribute to render them.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
asset-packagist.org
- Triggering command:
/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/3DlFYM /usr/bin/composer install --no-interaction(dns block)https://api.github.com/repos/mk-j/PHP_XLSXWriter/zipball/67541cff96eab25563aa7fcecba33e03368fa464
- Triggering command:
/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/t6R2OW /usr/bin/composer install --no-interaction(http block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
Original prompt
This section details on the original issue you should resolve
<issue_title>Soft new line support</issue_title> <issue_description>I cannot find a way to add soft new lines (ALT + ENTER in Excel) to have new lines within the same cell. Joining my array with
| join["\n"]puts the items in separate cells underneath each other, not in the same cell.I'm still on Craft CMS 2.7 btw.</issue_description>
<agent_instructions>Do we support this? If not, add support. Research dependencies and see if they support this.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
- Fixes sjelfull/craft3-beam#4
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.