react-export-table-to-excel vs xlsx
Exporting Data to Excel in React Applications
react-export-table-to-excelxlsxSimilar Packages:

Exporting Data to Excel in React Applications

react-export-table-to-excel and xlsx are both tools used to generate Excel files from JavaScript data, but they serve different architectural roles. react-export-table-to-excel is a high-level React component wrapper designed for quick integration, allowing developers to add an export button with minimal code. xlsx (also known as SheetJS) is a low-level, framework-agnostic library that provides comprehensive control over spreadsheet creation, parsing, and manipulation. While the former focuses on developer speed within React, the latter offers robust features for complex data handling across any JavaScript environment.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

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

React Export Table vs SheetJS: Component Wrappers vs Core Libraries

Both react-export-table-to-excel and xlsx enable JavaScript applications to generate Excel files, but they approach the problem from opposite ends of the abstraction spectrum. react-export-table-to-excel wraps the complexity into a React component, while xlsx exposes the raw tools needed to build spreadsheets from scratch. Let's compare how they handle common engineering tasks.

🧩 Integration Model: Component vs Utility

react-export-table-to-excel provides a pre-built React component.

  • You import the component and place it in your JSX.
  • It renders a button automatically and handles the click event internally.
  • Best for teams that want to avoid writing file-handling logic.
// react-export-table-to-excel: Drop-in component
import ReactExportTableToExcel from 'react-export-table-to-excel';

function ExportButton({ data }) {
  return (
    <ReactExportTableToExcel
      filename="Report"
      sheet="Sheet1"
      data={data}
    />
  );
}

xlsx is a utility library that requires manual wiring.

  • You import the library and call functions to create the file.
  • You must create your own button and attach an onClick handler.
  • Best for teams that need to separate UI from business logic.
// xlsx: Manual utility usage
import * as XLSX from 'xlsx';

function ExportButton({ data }) {
  const handleExport = () => {
    const ws = XLSX.utils.json_to_sheet(data);
    const wb = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
    XLSX.writeFile(wb, "Report.xlsx");
  };

  return <button onClick={handleExport}>Export</button>;
}

📊 Data Handling: Direct Props vs Sheet Conversion

react-export-table-to-excel accepts data directly as a prop.

  • Pass an array of objects straight to the component.
  • Keys become headers, values become cells automatically.
  • Less code, but less flexibility if data needs transformation.
// react-export-table-to-excel: Direct data prop
const userData = [
  { name: "Alice", role: "Dev" },
  { name: "Bob", role: "Design" }
];

<ReactExportTableToExcel data={userData} />;

xlsx requires converting data into a worksheet object first.

  • Use json_to_sheet to transform arrays into grid format.
  • Allows you to modify the worksheet before saving.
  • More verbose, but enables data cleaning or reordering.
// xlsx: Explicit sheet conversion
const userData = [
  { name: "Alice", role: "Dev" },
  { name: "Bob", role: "Design" }
];

const ws = XLSX.utils.json_to_sheet(userData);
// You can modify ws here before writing

🎨 Styling and Formatting: Limited vs Extensive

react-export-table-to-excel offers basic styling via props.

  • You can pass header styles or column widths as configuration.
  • Options are restricted to what the wrapper exposes.
  • Sufficient for simple reports but fails for complex branding.
// react-export-table-to-excel: Prop-based styling
<ReactExportTableToExcel
  data={data}
  headerStyle={{ fontSize: '20px', color: 'white' }}
  sheet="StyledSheet"
/>

xlsx supports full Excel styling specifications.

  • You define cell styles using standard Excel objects.
  • Control fonts, colors, borders, and number formats precisely.
  • Requires more code but matches professional report standards.
// xlsx: Cell-level styling
const ws = XLSX.utils.json_to_sheet(data);
ws["A1"].s = {
  font: { bold: true, color: { rgb: "FFFFFF" } },
  fill: { fgColor: { rgb: "4472C4" } }
};

📥 File Trigger: Automatic vs Manual Control

react-export-table-to-excel manages the download flow.

  • Clicking the rendered button triggers the download instantly.
  • No need to handle blob creation or URL revocation.
  • Convenient, but hides the underlying mechanism from you.
// react-export-table-to-excel: Automatic trigger
// The component handles the blob and anchor tag internally
<ReactExportTableToExcel data={data} filename="report.xlsx" />

xlsx leaves file creation and triggering to you.

  • You call writeFile to generate and download the blob.
  • Allows custom logic before download (e.g., API calls, logging).
  • More control over when and how the file is delivered.
// xlsx: Manual trigger
const handleDownload = () => {
  // Custom logic here (e.g., analytics tracking)
  console.log("Downloading report");
  XLSX.writeFile(wb, "report.xlsx");
};

🌐 Environment Support: React vs Universal

react-export-table-to-excel is tied to the React ecosystem.

  • Cannot be used in vanilla JS or Node.js scripts easily.
  • Adds React dependency to your bundle even for logic.
  • Limits reuse outside of React components.
// react-export-table-to-excel: React only
// Cannot use this in a Node.js cron job or vanilla script
import ReactExportTableToExcel from 'react-export-table-to-excel';

xlsx works anywhere JavaScript runs.

  • Compatible with React, Vue, Angular, Node.js, and browsers.
  • Same code can run on server-side for scheduled reports.
  • Promotes code sharing between frontend and backend.
// xlsx: Universal support
// Works in Node.js, React, or vanilla browser scripts
import * as XLSX from 'xlsx';
// Same logic applies in all environments

🤝 Similarities: Shared Ground Between Packages

While the implementation differs, both packages aim to solve the same core problem. Here are key overlaps:

1. 📄 Excel File Generation

  • Both produce .xlsx or .xls files readable by Excel.
  • Handle the underlying binary or XML structure for you.
// Both result in a downloadable Excel file
// react-export-table-to-excel: via component prop
// xlsx: via XLSX.writeFile

2. 🗂️ JSON Data Input

  • Both accept arrays of objects as the primary data source.
  • Map object keys to column headers automatically.
// Shared data structure
const data = [{ id: 1, name: "Test" }];
// Both packages can consume this format directly

3. 🌍 Browser Compatibility

  • Both run in modern browsers without plugins.
  • Rely on Blob APIs for client-side file downloads.
// Both utilize browser Blob capabilities
// No server-side processing required for basic exports

4. 🛠️ Open Source Availability

  • Both are free to use under permissive licenses.
  • Hosted on npm and GitHub for community contributions.
// Installation via npm
// npm install react-export-table-to-excel
// npm install xlsx

📊 Summary: Key Similarities

FeatureShared by Both
Output Format📄 .xlsx / .xls files
Data Source🗂️ JSON Arrays / Objects
Platform🌍 Client-side Browser Support
License🛠️ Open Source (npm)
Core Goal🚀 Export data to spreadsheets

🆚 Summary: Key Differences

Featurereact-export-table-to-excelxlsx
Type🧩 React Component🛠️ Utility Library
Setup⚡ Drop-in JSX🔧 Manual Function Calls
Styling🎨 Limited Props🖌️ Full Cell Control
Environment⚛️ React Only🌐 Universal (Node + Browser)
Control🤖 Automated🎯 Explicit
Maintenance⚠️ Wrapper Dependency✅ Industry Standard

💡 The Big Picture

react-export-table-to-excel is like a pre-made meal 🍱 — quick to serve and perfect for simple needs. Ideal for internal tools, admin dashboards, or prototypes where speed matters more than customization. It removes friction but locks you into its limited feature set.

xlsx is like a professional kitchen 🔪 — requires skill and setup but allows you to cook anything. Perfect for customer-facing reports, complex financial data, or server-side generation. It demands more code but ensures you never hit a ceiling on functionality.

Final Thought: While the wrapper offers convenience, xlsx is the safer long-term bet for production apps. Relying on a wrapper adds a layer of fragility; if the wrapper breaks, you are stuck. With xlsx, you own the logic and can adapt as requirements grow.

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

  • react-export-table-to-excel:

    Choose react-export-table-to-excel if you need a quick, drop-in solution for a simple table export button within a React app. It is best suited for standard dashboards or admin panels where the data structure is flat and styling requirements are basic. This package reduces boilerplate code significantly, allowing you to implement exports in minutes rather than hours. However, rely on it only for straightforward use cases, as it offers limited control over file formatting and depends on the maintenance of a third-party wrapper.

  • xlsx:

    Choose xlsx if you require full control over the Excel file structure, styling, or need to support complex data types like formulas and multiple sheets. It is the industry standard for spreadsheet manipulation and works in both browser and Node.js environments without React dependencies. This library is ideal for enterprise applications where report fidelity, performance, and long-term maintenance are critical. Be prepared to write more boilerplate code to handle the file generation and download logic manually.

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;