Using Beam

The starting point when working with Beam is to create a instance:

{% set options = {
    header: ['Email', 'Name'],
    content: [
        [ 'test@example.com', 'John Doe' ],
        [ 'another+test@example.com', 'Jane Doe' ],
        [ 'third+test@example.com', 'Trond Johansen' ],
    ]
} %}
{% set beam = craft.beam.create(options) %}

This will return a BeamModel behind the scenes.

If you want to append content dynamically, say from a loop, you can use the append method:

{% set myUserQuery = craft.users()
    .group('authors') %}

{# Fetch the users #}
{% set users = myUserQuery.all() %}

{# Display the list #}
{% for user in users %}
    {% do beam.append([user.username, user.name, user.email]) %}
{% endfor %}

To generate an CSV:

{% do beam.csv() %}

To generate an XLSX:

{% do beam.xlsx() %}

Changing config on the fly

To set the header of the file (the first row):

{% do beam.setHeader([ 'Username', 'Name', 'Email' ]) %}

To set the filename:

{% set currentDate = now|date('Y-m-d') %}
{% do beam.setFilename("report-#{currentDate}") %}

To overwrite the content:

{% do beam.setContent([
    [ 'test@example.com', 'John Doe' ],
    [ 'another+test@example.com', 'Jane Doe' ],
    [ 'third+test@example.com', 'Trond Johansen' ],
]) %}

Custom cell formatting is supported for XLSX:

{% set options = {
    header: ['Email', 'Name', { text: 'Number', type: 'number' }, { text: 'Date', type: 'date' }],
    content: [
        [ 'test@example.com', 'John Doe', 100000, '2022-06-10'],
        [ 'another+test@example.com', 'Jane Doe', 252323, '2022-06-22'],
        [ 'third+test@example.com', 'Trond Johansen', 30, '2022-06-22'],
        [ 'third+test@example.com', 'Trond Johansen', 6233, '2023-06-22'],
    ]
} %}
{% set beam = craft.beam.create(options) %}
{%  do beam.xlsx() %}

These types are supported:

Format TypeMaps to the following cell format
string@
integer0
dateYYYY-MM-DD
datetimeYYYY-MM-DD HH:MM:SS
timeHH:MM:SS
price#,##0.00
dollar[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00
euro#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]

Brought to you by Superbig

Installation Instructions

To install this plugin, copy the command above to your terminal.

Active Installs
201
Version
3.0.0
License
MIT
Compatibility
Craft 3, Craft 4, Craft 5
Last release
October 3, 2022
Activity (30 days)
1
Closed Issues
1
Open Issues
1
Merged PRs
0
Open PRs