Export Data in menu
Export Data options
Export Using Table Name
Export Using Code

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

Data Export Module

Table of Contents

  1. Introduction
  2. Installation and Setup
  3. Main Features
  4. How to Use the Data Export Module
  5. Additional Notes
  6. Conclusion

1. Introduction

The Data Export Module provides a robust solution for exporting data in various formats such as CSV, XLSX, PDF, and DOCX. This module is designed to offer flexible and dynamic export capabilities, allowing administrators and developers to export data from specific database tables or custom queries. It offers dynamic header and data configuration, which ensures that exported files are tailored to meet your needs.

2. Installation and Setup

To install and configure the Data Export Module:

  1. Download the Module: Download the Data Export Module from the Drupal module repository.
  2. Enable the Module: Go to Admin Menu > Extend and enable the Data Export module.
  3. Configure Permissions: Ensure that appropriate user roles have permission to access export functionalities. Navigate to People > Permissions to assign these.
  4. Install Required Libraries: Install the following libraries using Composer:
  • PhpSpreadsheet (for XLSX export):
composer require phpoffice/phpspreadsheet
  • PhpWord (for DOCX export):
  • composer require phpoffice/phpword
  • TCPDF (for PDF export):
  • composer require tecnickcom/tcpdf

    3. Main Features

    • Export Formats Supported: CSV, XLSX, PDF, DOCX.
    • Dynamic Data Export: Export data from any database table or through custom SQL queries.
    • Simple Interface: Select tables and columns easily.
    • Validation and Error Handling: Automatically checks for matching headers and data columns.
    • Developer-friendly: Hooks are available for customizing the export process programmatically.

    4. How to Use the Data Export Module

    a. Export Using Table Name

    1. Navigate to Export Interface: Go to Admin Menu > Export Data > Export Using Table Name.
    2. Enter Table Name: Input the name of the table from which to export data.
    3. Select Columns: Choose the columns to export. If none are selected, all columns will be included.
    4. Select Format: Choose between CSV, XLSX, DOCX, or PDF formats.
    5. Export: Click Export to download the file in your chosen format.

    b. Export Using Code

    1. Navigate to Custom SQL Export: Go to Admin Menu > Export Data > Export Using Code.
    2. Enter SQL Query: Input a valid SQL query for the data you want to export.
    3. Preview Data: Click Show Records to preview the query result.
    4. Select Format: Choose your export format (CSV, XLSX, DOCX, PDF).
    5. Export: Click Export to generate and download the file.

    c. Developer Hooks

    The Data Export Module provides several hooks to programmatically manage and customize exports. These hooks allow developers to pass dynamic headers and data arrays:

    • exportPdf($headers, $data): Exports data in PDF format using TCPDF.
    • exportDocx($headers, $data): Exports data in DOCX format with a table structure.
    • exportCsv($headers, $data): Generates a CSV file.
    • exportXlsx($headers, $data): Exports data in XLSX format.

    Validation and Error Handling: The functions validate that the number of columns in the headers matches the number of columns in the data. If not, an error message is returned: "Error: The number of columns in headers and data does not match."

    5. Additional Notes

    Passing Headers and Data

    The $headers array contains the column titles, and the $data array is multi-dimensional with each sub-array representing a row of data.

    $headers = ['ID', 'Name', 'Email'];
    $data = [
        ['1', 'John Doe', 'john.doe@example.com'],
        ['2', 'Jane Smith', 'jane.smith@example.com'],
    ];
        

    Headers: 'ID', 'Name', and 'Email' will be the column titles.

    Data: Values populate under each header as records.

    6. Conclusion

    The Data Export Module streamlines data export processes for Drupal administrators and developers. By following the installation and usage instructions, you can efficiently manage your data exports. The module also offers hooks for programmatically customizing the export, making it a versatile tool for advanced use cases. This module is a valuable asset for teams that frequently need to export data for reporting, analysis, or record-keeping.

    Supporting organizations: 

    Project information

    Releases