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 :: javascript join object properties in array 
Javascript :: React count up on scroll 
Javascript :: discord.js emoji in embed 
Javascript :: moment compare time 
Javascript :: jquery submit form 
Javascript :: javascript regex example match 
Javascript :: get bottom position of element javascript 
Javascript :: instantiate template playcanvas 
Javascript :: delete node module 
Javascript :: jquery on form submit call function 
Javascript :: axio post file 
Javascript :: replace many chracters js 
Javascript :: javascript object destructuring 
Javascript :: node require module 
Javascript :: how to flip a Number in javascript 
Javascript :: get current time in different timezone javascript 
Javascript :: redondear decimales javascript 
Javascript :: Uncaught TypeError: .replace is not a function 
Javascript :: import bootstrap in react 
Javascript :: bindparam 
Javascript :: moment js between two dates 
Javascript :: fetch api in js 
Javascript :: react-file-base64 
Javascript :: javascript pseudo random 
Javascript :: javascript variable with multiline text 
Javascript :: convert date and time into epoch javascript 
Javascript :: nodejs delete s3 folder 
Javascript :: how to make a div appear when clicked on in javascript 
Javascript :: Find the maximum number in a jagged array of numbers 
Javascript :: how to create a folder using fs in node js 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =