react-json-to-excel
v1.0.8
Published
Download the json as excel
Downloads
7,125
Maintainers
Readme
React json to excel
Install
npm install react-json-to-excel --save
Peer modules
npm install file-saver xlsx --save
npm install react-json-to-excel --save
Using Button Component
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"
/>
);
}
}
Usage
import { 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"
/>
);
}
}
Using exportToExcel Method
import { exportToExcel } from 'react-json-to-excel';
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 (
<button onClick={() => exportToExcel(samplejson2, 'downloadfilename')}>
Download using method
</button>
);
}
}
Using exportToExcel Method For Multiple sheets
- Data object should be as below
- exportToExcel(data, 'downloadfilename', true ) - should pass true
[{
sheetName:"sheet1",
details:[{ name: 'name01', age: '20', sex: 'M' },
{ name: 'name02', age: '22', sex: 'F' },
{ name: 'name03', age: '20', sex: 'M' }]
},{
sheetName:"sheet2",
details:[{ name: 'name01', age: '20', sex: 'M' },
{ name: 'name02', age: '22', sex: 'F' },
{ name: 'name03', age: '20', sex: 'M' }]
}]
import { exportToExcel } from 'react-json-to-excel';
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 (
<button onClick={() => exportToExcel(samplejson2, 'downloadfilename', true )}>
Download using method
</button>
);
}
}
PROPTYPES
| Prop | Type | Info | | ------------ | ------ | -------------------------------------------------------- | | title | String | name of the button | | btnClassName | String | class name added to the the button for css customization | | data | Array | array of objects | | fileName | String | download file name | | btnColor | String | color of button defatlt to #4CAF50 |