Export json to excel reactjs
I have an endpoint that retrieves a json object like the following: Show
And I want to implement a button that will allow the user to export the data to multiple formats, including Excel (.xlsx) but I don't really know were to start. I've already seen libraries that realize this, but I don't feel comfortable because they usually have less than 1.5k downloads per week. My purpose is to export an Excel document with a simple table where the headers are going to be the attributes of the objects. asked Jan 26 at 22:52
2 Use xlsx third-party library.
Using Library:
Download function trigger at button click(pass data as argument):
Download Button: (function call: you should modify it as per your requirement, below one is React Class Component implementation, that's why I used
answered Jan 27 at 0:04
AnmolAnmol 3543 silver badges5 bronze badges 3 Based on the accepted answer, in case someone is getting the "Attempted import error: 'xlsx' does not contain a default export (imported as 'XLSX')" error, try importing using the following:
Hope it helps. answered May 4 at 23:35
1.0.4 • Public • Published a year ago
[ Install
Usage
import { JsonToExcel } from "react-json-to-excel"; class SmapleComponent extends Component { render() { return ( <JsonToExcel title="Download as Excel" data={[{ test: "test" }]} fileName="sample-file" btnClassName="custom-classname" /> ); } } Usageimport { JsonToExcel } from "react-json-to-excel"; const samplejson1 = [ { label: "C" }, { label: "Java" }, { label: "Go" }, { label: "Javascript" }, { label: "HTML" }, { label: "CSS" }, { label: "REACT" }, { label: "JQUERY" } ]; const samplejson2 = [ { name: "name01" , age:"20",sex:"M" }, { name: "name02" , age:"22",sex:"F" } { name: "name03" , age:"20",sex:"M" } ]; class SmapleComponent2 extends Component { render() { return ( <JsonToExcel title="Download as Excel" data={samplejson} fileName="sample-file" /> <JsonToExcel title="Download as Excel" data={samplejson2} fileName="sample-file" /> ); } } Example PROPTYPES
react-json-to-excelKeywords
How do I export JSON data to Excel in react?React.Js Code. import React, { Component } from 'react';. import exportFromJSON from 'export-from-json'. const data = [{ foo: 'foo' }, { bar: 'bar' }]. const fileName = 'download'. const exportType = 'xls'. class App extends Component {. ExportToExcel = () => {. exportFromJSON({ data, fileName, exportType }). How do I pull JSON into Excel?File: JSON. Select Data > Get Data > From File > From JSON. The Import Data dialog box appears.. Locate the JSON file, and then select Open.. How do I export from react to excel?Getting Started. Install kendo-react-excel-export package. ... . Import the ExcelExport component in your React Application. ... . Wrap the Grid in the ExcelExport component and use the ExcelExport save function to export the Grid and save it to excel file.. How do I export JSON data to Excel in node JS?Node. js has multiple packages to export JSON to excel format.. Step 1: Creating the user list. We create the user list. ... . Step 2: Defining the logic in the user controller. Next, we will write the logic for downloading excel in the User controller. ... . Step 3: Creating a new workbook object.. |