
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
react-export-table-to-excel
Advanced tools
It allows you to export an HTML table just by sending the table reference and the name with which you want the file to be saved
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;
FAQs
It allows you to export an HTML table just by sending the table reference and the name with which you want the file to be saved
The npm package react-export-table-to-excel receives a total of 8,134 weekly downloads. As such, react-export-table-to-excel popularity was classified as popular.
We found that react-export-table-to-excel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.