Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to upload an Excel sheet file using react.js and display data to a table

// react-excel-renderer
// There's a perfect library exactly for this ! It converts the excel data to JSON first, then renders it into a HTML table. Its called react-excel-renderer

+ Install it npm install react-excel-renderer --save

+ Import both components ExcelRenderer and OutTable
  import {ExcelRenderer, OutTable} from 'react-excel-renderer';

+ Provide the file object to the ExcelRenderer function in your event handler

// Code:

fileHandler = (event) => {
let fileObj = event.target.files[0];

//just pass the fileObj as parameter
ExcelRenderer(fileObj, (err, resp) => {
  if(err){
    console.log(err);            
  }
  else{
    this.setState({
      cols: resp.cols,
      rows: resp.rows
    });
  }
});               

}

// Once JSON is obtained, provide it to the OutTable component
<OutTable data={this.state.rows} columns={this.state.cols} tableClassName="ExcelTable2007" tableHeaderRowClass="heading" />
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript Using splice() to Remove Elements 
Javascript :: delete folder with deno 
Javascript :: vue select first option default 
Javascript :: get param from url jquery 
Javascript :: javascript int to string 
Javascript :: js fetch json 
Javascript :: Date object for local time and date 
Javascript :: react native gif dont work 
Javascript :: javascript remainder function 
Javascript :: context api react 
Javascript :: dynamic button click in javascript 
Javascript :: code for javascript message box 
Javascript :: javascript es6 find 
Javascript :: auto scroll to view react-native 
Javascript :: get all data attributes jquery from multiple elements 
Javascript :: mongoose user model example 
Javascript :: unzip file electronjs 
Javascript :: SyntaxError: await is only valid in async function 
Javascript :: The element.InnerHTML Property 
Javascript :: moment format heure 
Javascript :: global variable vuejs 
Javascript :: Remove duplicate items in an array 
Javascript :: paragraph antd 
Javascript :: js scroll to bottom exact 
Javascript :: react POST ERROR HANDLING 
Javascript :: js replace 
Javascript :: react maps 
Javascript :: discord.js create permanent invite 
Javascript :: jquery find input and select 
Javascript :: nextelementsibling javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =