react-export-table-to-excel vs xlsx
Excel Export Libraries for Web Development
react-export-table-to-excelxlsxSimilar Packages:

Excel Export Libraries for Web Development

These libraries facilitate the export of data from web applications to Excel files, enabling users to download structured data in a familiar format. 'react-export-table-to-excel' is specifically designed for React applications, providing a straightforward way to export HTML tables to Excel. In contrast, 'xlsx' is a more versatile library that allows for reading, writing, and manipulating Excel files in various formats, making it suitable for broader use cases beyond just exporting tables.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-export-table-to-excel04118.4 kB15-ISC
xlsx036,2377.5 MB132-Apache-2.0

Feature Comparison: react-export-table-to-excel vs xlsx

Ease of Use

  • react-export-table-to-excel:

    This library is designed for simplicity and ease of integration within React applications. It allows developers to quickly set up table exports with minimal code, making it user-friendly for those who need basic functionality without a steep learning curve.

  • xlsx:

    While 'xlsx' offers extensive functionality, it comes with a steeper learning curve due to its more complex API. Developers may need to invest time in understanding its features and how to implement them effectively, especially for advanced use cases.

Functionality

  • react-export-table-to-excel:

    Primarily focused on exporting HTML tables to Excel, this library provides a straightforward solution for converting table data into an Excel format. It does not support reading or manipulating existing Excel files, making it less versatile than 'xlsx'.

  • xlsx:

    This library supports a wide range of functionalities, including reading, writing, and manipulating Excel files in various formats (XLSX, CSV, etc.). It allows for comprehensive data manipulation, making it suitable for applications that require more than just exporting data.

Integration

  • react-export-table-to-excel:

    Seamlessly integrates with React applications, leveraging React's component model to provide a straightforward export mechanism. This makes it an excellent choice for developers already using React who want to add export functionality quickly.

  • xlsx:

    Can be used in any JavaScript environment, including Node.js and browsers, making it highly versatile. However, it may require additional setup and configuration to work effectively in a React context.

Customization

  • react-export-table-to-excel:

    Offers limited customization options for the exported Excel file. It focuses on exporting the data as it appears in the HTML table, which may not suit all use cases that require specific formatting or additional data manipulation.

  • xlsx:

    Provides extensive customization capabilities, allowing developers to format cells, create multiple sheets, and manipulate data before exporting. This flexibility makes it ideal for complex applications that need tailored Excel outputs.

Community and Support

  • react-export-table-to-excel:

    As a smaller library, it may have a more limited community and fewer resources available for troubleshooting or advanced use cases. However, it is straightforward enough that many common issues can be resolved quickly through documentation.

  • xlsx:

    Has a larger community and more extensive documentation, which can be beneficial for developers seeking support or examples. The widespread use of this library means that many common problems have been addressed by the community.

How to Choose: react-export-table-to-excel vs xlsx

  • react-export-table-to-excel:

    Choose 'react-export-table-to-excel' if you are working within a React application and need a simple, quick solution to export HTML tables directly to Excel without additional configuration or complexity.

  • xlsx:

    Choose 'xlsx' if you require more advanced features such as reading existing Excel files, manipulating data, or exporting various types of data structures beyond just HTML tables. This library is ideal for applications that need comprehensive Excel file handling capabilities.

README for react-export-table-to-excel

ReactExportTableToExcel

Provides a client side generation of Excel (.xls) file from HTML table element.

NPM


No additional dependencies


ReactExportTableToExcel's samples in React.js ( CodeSandbox )

ReactExportTableToExcel's samples in Next.js ( CodeSandbox )


Installation

npm install react-export-table-to-excel
yarn add react-export-table-to-excel

Features

  • Download HTML table as Excel file in .xls format
  • No server side code
  • Set desired .xls filename and sheet
  • Hook to export to excel
  • Component to export to excel
  • Method to export to excel

Options

  • Component

A list of available properties can be found below. These must be passed to the containing DownloadTableExcel component.

PropertyTypeDescription
filenamestringName of Excel file.
sheetstringName of Excel sheet.
childrenReactElementcomponent that will obtain the onClick event to export to excel (the most common is a button).
currentTableRefHTMLElementthe current of the table reference.

Example

import React, {useRef} from 'react';
import { DownloadTableExcel } from 'react-export-table-to-excel';

const Test = () =>  {
    const tableRef = useRef(null);

        return (
            <div>
                <DownloadTableExcel
                    filename="users table"
                    sheet="users"
                    currentTableRef={tableRef.current}
                >

                   <button> Export excel </button>

                </DownloadTableExcel>

                <table  ref={tableRef}>
                 <tbody>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Age</th>
                    </tr>
                    <tr>
                        <td>Edison</td>
                        <td>Padilla</td>
                        <td>20</td>
                    </tr>
                    <tr>
                        <td>Alberto</td>
                        <td>Lopez</td>
                        <td>94</td>
                    </tr>
                  </tbody>
                </table>

            </div>
        );
    }
}

export default Test
  • Hook

A list of available properties can be found below. These must be passed to the containing useDownloadExcel hook.

PropertyTypeDescription
filenamestringName of Excel file.
sheetstringName of Excel sheet.
currentTableRefHTMLElementthe current of the table reference.

Example

import React, {useRef} from 'react';
import { useDownloadExcel } from 'react-export-table-to-excel';

const Test = () =>  {
    const tableRef = useRef(null);

    const { onDownload } = useDownloadExcel({
        currentTableRef: tableRef.current,
        filename: 'Users table',
        sheet: 'Users'
    })

        return (
            <div>
                <button onClick={onDownload}> Export excel </button>

                 <table  ref={tableRef}>
                  <tbody>
                    <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Age</th>
                    </tr>
                    <tr>
                        <td>Edison</td>
                        <td>Padilla</td>
                        <td>20</td>
                    </tr>
                    <tr>
                        <td>Alberto</td>
                        <td>Lopez</td>
                        <td>94</td>
                    </tr>
                  </tbody>
                </table>

            </div>
        );
    }
}

export default Test

  • Method

A list of available properties can be found below. These must be passed to the downloadExcel method.

PropertyTypeDescription
filenamestringName of Excel file.
sheetstringName of Excel sheet.
tablePayloadobjectpayload to download excel.

Example

import React from "react";
import { downloadExcel } from "react-export-table-to-excel";

const Test = () => {
  const header = ["Firstname", "Lastname", "Age"];
  const body = [
    ["Edison", "Padilla", 14],
    ["Cheila", "Rodrigez", 56],
  ];

  /**
   * @description:
   *  also accepts an array of objects; the method (downloadExcel) will take
   *  as order of each column, the order that each property of the object brings with it.
   *  the method(downloadExcel) will only take the value of each property.
   */
  const body2 = [
    { firstname: "Edison", lastname: "Padilla", age: 14 },
    { firstname: "Cheila", lastname: "Rodrigez", age: 56 },
  ];

  function handleDownloadExcel() {
    downloadExcel({
      fileName: "react-export-table-to-excel -> downloadExcel method",
      sheet: "react-export-table-to-excel",
      tablePayload: {
        header,
        // accept two different data structures
        body: body || body2,
      },
    });
  }

  return (
    <div>
      <button onClick={handleDownloadExcel}>download excel</button>

      <table>
        <tbody>
          <tr>
            {header.map((head) => (
              <th key={head}> {head} </th>
            ))}
          </tr>

          {body.map((item, i) => (
            <tr key={i}>
              {item.map((it) => (
                <td key={it}>{it}</td>
              ))}
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
};

export default Test;