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.
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.
react-export-table-to-excel provides a pre-built React component.
// 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.
onClick handler.// 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>;
}
react-export-table-to-excel accepts data directly as a prop.
// 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.
json_to_sheet to transform arrays into grid format.// 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
react-export-table-to-excel offers basic styling via props.
// react-export-table-to-excel: Prop-based styling
<ReactExportTableToExcel
data={data}
headerStyle={{ fontSize: '20px', color: 'white' }}
sheet="StyledSheet"
/>
xlsx supports full Excel styling specifications.
// 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" } }
};
react-export-table-to-excel manages the download flow.
// 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.
writeFile to generate and download the blob.// xlsx: Manual trigger
const handleDownload = () => {
// Custom logic here (e.g., analytics tracking)
console.log("Downloading report");
XLSX.writeFile(wb, "report.xlsx");
};
react-export-table-to-excel is tied to the React ecosystem.
// 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.
// xlsx: Universal support
// Works in Node.js, React, or vanilla browser scripts
import * as XLSX from 'xlsx';
// Same logic applies in all environments
While the implementation differs, both packages aim to solve the same core problem. Here are key overlaps:
.xlsx or .xls files readable by Excel.// Both result in a downloadable Excel file
// react-export-table-to-excel: via component prop
// xlsx: via XLSX.writeFile
// Shared data structure
const data = [{ id: 1, name: "Test" }];
// Both packages can consume this format directly
// Both utilize browser Blob capabilities
// No server-side processing required for basic exports
// Installation via npm
// npm install react-export-table-to-excel
// npm install xlsx
| Feature | Shared 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 |
| Feature | react-export-table-to-excel | xlsx |
|---|---|---|
| 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 |
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.
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.
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.
Provides a client side generation of Excel (.xls) file from HTML table element.
npm install react-export-table-to-excel
yarn add react-export-table-to-excel
A list of available properties can be found below. These must be passed to the containing DownloadTableExcel component.
| Property | Type | Description |
|---|---|---|
| filename | string | Name of Excel file. |
| sheet | string | Name of Excel sheet. |
| children | ReactElement | component that will obtain the onClick event to export to excel (the most common is a button). |
| currentTableRef | HTMLElement | the current of the table reference. |
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
A list of available properties can be found below. These must be passed to the containing useDownloadExcel hook.
| Property | Type | Description |
|---|---|---|
| filename | string | Name of Excel file. |
| sheet | string | Name of Excel sheet. |
| currentTableRef | HTMLElement | the current of the table reference. |
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
A list of available properties can be found below. These must be passed to the downloadExcel method.
| Property | Type | Description |
|---|---|---|
| filename | string | Name of Excel file. |
| sheet | string | Name of Excel sheet. |
| tablePayload | object | payload to download excel. |
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;