npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2025 โ€“ย Pkg Stats / Ryan Hefner

react-json-excel-exporter

v1.1.1

Published

๐Ÿ“Š react-json-excel-exporter A simple, React-friendly library for exporting JSON data into Excel/CSV files directly from the frontend. It uses exceljs and file-saver under the hood.

Downloads

209

Readme

๐Ÿ“Š react-json-excel-exporter A simple, React-friendly library for exporting JSON data into Excel/CSV files directly from the frontend. It uses exceljs and file-saver under the hood.

โœจ Features ๐Ÿ“ฆ Export JSON data directly to .xlsx or .csv files.

๐ŸŽจ Automatically generates headers from JSON keys.

๐Ÿ–‹๏ธ Supports custom column names and custom column order.

๐Ÿ—“๏ธ Supports Year, Month, Date Range, or single Date in reports.

๐Ÿงฎ NEW: Supports info (summary) table with label/value pairs

โšก Works seamlessly in React or any plain JavaScript environment.

๐Ÿ”ฅ No backend required; everything happens on the client side.

๐Ÿ“ฆ Installation

Install the package

via npm:

npm install react-json-excel-exporter

Or

via yarn:

yarn add react-json-excel-exporter

Note: exceljs and file-saver are included automatically as dependencies. You don't need to install them separately.

๐Ÿš€ Quick Usage Here's a simple example of how to use the library within a React component:

import { generateExcel } from "react-json-excel-exporter"

function App() {
  const data = [
    { Name: "Omal", Age: 25, Country: "Sri Lanka" },
    { Name: "Kelum", Age: 24, Country: "Sri Lanka" },
  ]

  const info = [
    { label: "Present", value: 5 },
    { label: "Absent", value: 1 },
    { label: "Idle", value: 21 },
    { label: "TotalCount", value: 27 },
  ]

  // 1. Normal download (default headers) with info
  const handleNormalDownload = () => {
    generateExcel({
      filename: "UsersReport_Normal",
      data,
      info,
      date: "2025-09-20",
    })
  }

  // 2. Custom headers (rename columns)
  const handleCustomHeaders = () => {
    generateExcel({
      filename: "UsersReport_CustomHeaders",
      data,
      headers: ["Full Name", "Age (Years)", "Country of Residence"], // order from JSON keys
      year: "2025",
    })
  }

  // 3. Custom headers + custom order
  const handleCustomOrder = () => {
    const headers = [
      { label: "Country of Residence", value: "Country" },
      { label: "Full Name", value: "Name" },
      { label: "Age (Years)", value: "Age" },
    ]

    generateExcel({
      filename: "UsersReport_CustomOrder",
      data,
      headers,
      fromdate: "2025-09-01",
      todate: "2025-09-20",
      type: "csv", // can be "xlsx" or "csv"
    })
  }

  return (
    <div style={{ padding: "2rem" }}>
      <h1>React JSON Excel Exporter Demo</h1>
      <button onClick={handleNormalDownload}>Normal Download</button>
      <button onClick={handleCustomHeaders} style={{ margin: "0 1rem" }}>
        Custom Headers
      </button>
      <button onClick={handleCustomOrder}>Custom Headers + Order</button>
    </div>
  )
}

export default App

Clicking this button will download an Excel file with a name like UsersReport_2025-09-19T12-30-00.xlsx.

๐Ÿ“ API Reference

The generateExcel function accepts a single options object with the following properties:

| Option | Type | Required | Description | | :--------- | :---------------- | :----------- | :-------------------------------------------------------------------------------------------------------------------- | | filename | string | Required | Base name for the Excel file (e.g., "UsersReport"). Timestamp and .xlsx extension are added automatically. | | data | array | Required | Array of JSON objects to export. Each object becomes a row in the spreadsheet. | | headers | array | Optional | Array of { label: string, value: string } for custom headers and column order. If not provided, JSON keys are used. | | year | string | Optional | Adds a "Year: [year]" header row to the Excel sheet. | | month | string | Optional | Adds a "Month: [month]" header row to the Excel sheet. | | fromdate | string | Optional | Start date for date range (e.g., "2025-01-01"). Must be used with todate. | | todate | string | Optional | End date for date range (e.g., "2025-01-31"). Must be used with fromdate. | | date | string | Optional | Single date (e.g., "2025-09-20"). Takes precedence over year/month/date range. | | info | string | Optional | NEW: Adds a summary/metrics/info table at the top of the Excel file. range. | | type | "xlsx" or "csv" | Optional | Export file type. Default is "xlsx". |

Export to Sheets

๐Ÿ“š Example Outputs

Example 1: With Year


generateExcel({
filename: "SalesReport",
data: [{ Product: "Shoes", Price: 100 }, { Product: "Bag", Price: 50 }],
year: "2025",
});
This will produce an Excel file with the following content:

Report Title - SalesReport Year: 2025

| Product | Price | | :------ | :---- | | Shoes | 100 | | Bag | 50 |

Example 2: With Date Range


generateExcel({
filename: "Attendance",
data: [{ Name: "Omal", Status: "Present" }, { Name: "Kelum", Status: "Absent" }],
fromdate: "2025-01-01",
todate: "2025-01-31",
});

This will produce an Excel file with the following content:

Report Title - Attendance Date Range: 2025-01-01 - 2025-01-31

| Name | Status | | :---- | :------ | | Omal | Present | | Kelum | Absent |