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

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 componentdidmount in function 
Javascript :: decode jwt token in angular 
Javascript :: empty an array in javascript 
Javascript :: javascript number reverse 
Javascript :: jquery equivalent of number_format( 
Javascript :: object.map() nest js 
Javascript :: javascript declare multiple variables on one line 
Javascript :: get class name of object javascript 
Javascript :: var vs let javascript 
Javascript :: javascript interview questions interviewbit 
Javascript :: javascript find vs filter 
Javascript :: javascript last element 
Javascript :: how to remove duplicates in js 
Javascript :: for-of loop 
Javascript :: js pow function 
Javascript :: babel core cdn 
Javascript :: how in javascript can display date and select image 
Javascript :: The DOM Parent-Child Relationship 
Javascript :: java script layout engine error 
Javascript :: javascript Rethrow an Exception 
Javascript :: fetch second parameters 
Javascript :: javascript function invocation 
Javascript :: jQuery - Set 
Javascript :: query middleware in express 
Javascript :: set display size phaser 
Javascript :: phaser shift position 
Javascript :: test unitaire javascript 
Javascript :: after end time run function 
Javascript :: TypeError: (0 , import_dev.useParams) is not a function remix 
Javascript :: Self Invoking Function ($()) That Can Be Reused 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =