How to export data to excel using React JS | Export data to Excel.

preview_player
Показать описание
How to export data to excel using React JS | Export data to Excel.

Steps:
1. Create a new project
npx create-react-app react-data-to-excel
2. Run project locally
npm start
3. npm install xlsx file-saver axios

link for the below files:

import React from 'react'
import * as FileSaver from "file-saver";
import * as XLSX from "xlsx";

export const ExportToExcel = ({ apiData, fileName }) = {
const fileType =
const fileExtension = ".xlsx";

const exportToCSV = (apiData, fileName) = {
const wb = { Sheets: { data: ws }, SheetNames: ["data"] };
const excelBuffer = XLSX.write(wb, { bookType: "xlsx", type: "array" });
const data = new Blob([excelBuffer], { type: fileType });
};

return (
button onClick={(e) = exportToCSV(apiData, fileName)} Export /button
);
};

import React from 'react'
import axios from 'axios'

import {ExportToExcel} from './ExportToExcel'

function App() {
const fileName = "myfile"; // here enter filename for your excel file

const fetchData = () ={

// reshaping the array
}))

setData(customHeadings)
})
}
fetchData()
}, [])

return (
div className="App"
ExportToExcel apiData={data} fileName={fileName} /
/div
);
}

export default App;

Next Steps :

---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
Must Watch Playlists

---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------

#javascript
#reactjs
#excel
Рекомендации по теме
welcome to shbcf.ru