Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

export data to excel using react js

import React from 'react'
import * as FileSaver from "file-saver";
import * as XLSX from "xlsx";
import { Button } from 'antd';
import { FileExcelOutlined } from '@ant-design/icons';

export const ExportToExcel = ({ apiData, fileName }) => {
  const fileType =
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8";
  const fileExtension = ".xlsx";

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

  return (
    <Button icon={<FileExcelOutlined />} type='primary' onClick={(e) => exportToCSV(apiData, fileName)}>Exporter</Button>
  );
};
Comment

read and save excel with react

import readXlsxFile from 'read-excel-file'
const input = document.getElementById('input') 
input.addEventListener('change', () => { 
  readXlsxFile(input.files[0]).then((rows) => { 
    // `rows` is an array of rows    // each row being an array of cells. 
  })})
Comment

read and save excel with react

import readXlsxFile from 'read-excel-file' const input = document.getElementById('input') input.addEventListener('change', () => {  readXlsxFile(input.files[0]).then((rows) => {    // `rows` is an array of rows    // each row being an array of cells.  })})
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native time range picker 
Javascript :: useReducer() hook react 
Javascript :: What are "res" and "req" parameters in Express functions 
Javascript :: javascript loading animation on button click 
Javascript :: react-drag-drop-files open twice 
Javascript :: what is random state 
Javascript :: react throttle render 
Javascript :: comming soon page in react 
Javascript :: notify js 
Javascript :: send data from form to another page angular 
Javascript :: how to install javascript 
Javascript :: insert a data into mongo using express 
Javascript :: javascript map() method 
Javascript :: create object filter 
Javascript :: jq append value to array 
Javascript :: jwt decode 
Javascript :: react router native back button 
Javascript :: null vs undefined 
Javascript :: base64 from file 
Javascript :: make indexOF in js 
Javascript :: javascript draw canvas grid 
Javascript :: how to generate angular component with scss 
Javascript :: jquery OR operation 
Javascript :: angular js 
Javascript :: heap javascript 
Javascript :: populate in mongoose 
Javascript :: context api in react 
Javascript :: Uncaught ReferenceError: function is not defined 
Javascript :: npx for yarn 
Javascript :: Array#splice 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =