This project is not covered by Drupal’s security advisory policy.

This module provides an Excel encoder via LibXL Library (commerce) for the Drupal 8 Serialization API. This enables the XLS and XLSX format to be used for data output.

PHP extension uses libXl library to provide API for generating or parsing all Excel files.
LibXL is a high-performance mechanism for working with Excel files and is able to generate output readable on Blackberries, iPhone, Office Products, Numbers, etc...
Additional information: LibXL, PHP Extension (iliaal/php_excel)

LibXL + php_excel - is the fastest option with perfect perfomance and low memory usage for PHP import/export functionality to Excel.

Small comparison:

*** PHPExcel:

Without caching:
Rows | Time | Memory usage | Memory per cell
10k | 70s | 370 Mb | 2.4 Kb
50k | 10m | 1790 Mb | 2.4 Kb

Caching (cache_in_memory_gzip):
Rows | Time | Memory usage | Memory per cell
10k | 110s | 181 Mb | 1.2 Kb
50k | 10m | 865 Mb | 1.1 Kb
100k | 20m | 1718 Mb | 1.1 Kb

Caching (cache_to_disc):
Rows | Time | Memory usage | Memory per cell
10k | 90 | 218 Mb | 1.4 Kb

*** LibXL:
Rows | Time | Memory usage |
100k | 25s | 1100 Mb |
200k | 50s | 2200 Mb |
300k | 85s | 3500 Mb |

For example:
Drupal 8's REST module can return data in XLS/XLSX format.
Views can output XLS/XLSX data via a 'REST Export' view.

Module developers can leverage XLS/XLSX as a format when using the Serialization API.
Installation:

  • Compile and install PHP Extension.
  • Enable the excel_libxl module.

Creating an XLS/XLSX export via Views.

  1. Create a new view
  2. Add a REST Export view.
  3. Check only 'xls' or 'xlsx' for the accepted request formats under Format > Data export > Settings.
  4. Add desired fields to the view.
  5. Change labels for fields in the view (used as Table Header).
  6. Add a path.

Usage Examples:

    $serializer = \Drupal::service('serializer');
    $header = [
      'number_field' => [
        'data' => t('Number field'),
        'xls_data' => [
          'type' => 'number',
          // Usually not required because is_numeric() is used
          // Should be: In case the data has markup or some text - '10,100.34 usd'
          'thousand_separator' => ',',
          // (optional)
          'decimal_separator' => '.',
          // (optional)
          'custom_cell_format' => ''
          // (optional) See below.
        ],
      ],
      'date_field' => [
        'data' => t('Date field'),
        'xls_data' => [
          'type' => 'date',
          'date_format' => 'Y-m-d', // (optional)  if not exist, strtotime() is used
          'custom_cell_format' => '' // (optional) See below.
        ],
      ],
      'currency_field' => [
        'data' => t('Currency field'),
        'xls_data' => [
          'type' => 'currency', // Intl PHP extension is used. \NumberFormatter.
          'locale' => 'en_US', // (optional) if not exist, 'en_US' is used.
          'currency' => 'USD', //(optional) if not exist, 'USD' is used.
          // (optional) XLSx cell format, if not exist, used as an example.
          'custom_cell_format' => '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)',
          'range_fx' => 'SUM', //(optional) Column range formula for the data. Example spreadsheet result - SUM(A2:A45).
        ],
      ],
    ];
    $context['header'] = $header;
    $output = $serializer->serialize($rows, 'xlsx', $context);

Project information

Releases