wabisoft / spreadsheetobject
CSV, XLS and XLSX files to code to use in Twig.
Installs: 67
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:craft-plugin
Requires
- php: ^8.0
- craftcms/cms: ^4.0.0
- phpoffice/phpspreadsheet: ^1.23
- wabisoft/framework: ^1.1.0
Requires (Dev)
README
{% set table = spreadsheetobject(asset) %}
This returns an array of items:
- title
- columnCount
- rows
{% if table %} Name of imported sheet: {{ table.title }} Total Columns: {{ table.columnCount }} <table> {% for row in table.rows %} <tr> {% for column in row %} <td>{{ column }}</td> {% endfor %} </tr> {% endfor %} </table> {% endif %}
Options
Supports:
sheet
- integer of the sheet to import. Defaults to 1;removeRow
- integer of row to delete. Defaults to falseremoveColumn
- letter value of column to delete. Defaults to falseremoveColumnByIndex
- index value, starting at 1, of column to delete. Defaults to false
Example:
{% set table = asset | spreadsheetobject({ 'removeRow': 1, 'removeColumnByIndex': 1 }) %} %}
Configuration Options
If the table results should be stored in the database for subsequent reading.
'storeInDb' => true
Commands
Plugin will watch for deleted and updated assets but if you want to flush all the records:
craft spreadsheet-object/flush/all
Helper Macro
A helper macro is exposed at _table-helper
which is compatible with table, row and cells.
A simple table example:
{% import '_table-helper' as tableHelper %}
{% set table = asset | spreadsheetobject %}
{{ tableHelper.table(table) }}
Full example:
{% import '_table-helper' as tableHelper %}
{% set table = asset | spreadsheetobject %}
{{ tableHelper.table(table, {
thead: false,
tfoot: false,
classes: {
table: false,
tr: false,
td: false,
th: false,
thead: false,
tfoot: false,
first: {
tr: false,
td: false,
th: false,
},
last: {
tr: false,
td: false,
th: false
}
}
}) }}
See: template code
Row only example
{% import '_table-helper' as tableHelper %}
{% set table = asset | spreadsheetobject %}
<table>
{% for row in table.rows %}
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
{{ tableHelper.tr(row) }}
{% endfor %}
</table>
Row helper accepts same options object as full table
See: template code