2

I have an excel file stored in src folder. I want to use react to read the excel file directly instead of uploading a file using input field and show the object array to the console, does anyone know how to do it? Any reference link about that? I saw a lot about uploading an excel file and output the data, but I don't want to upload the file. I want to import the file directly or fetch data from the file. Let me know if you know how to do in react. Thanks.

2 Answers 2

1

You could use FileReader API. Here's a link to similar question. You could parse/read the excel file using this package.

A little suggestion, would be to use .csv or .json files instead of .xlsx files, if you are only dealing in data.

Sign up to request clarification or add additional context in comments.

Comments

0
  fetch(excelFile).then((res) => res.arrayBuffer())
       .then((ab) => {
           const wb        = XLSX.read(ab, { type: "array" });
           const sheetname = wb.SheetNames[0]
           const ws        = wb.Sheets[sheetname]
           const json      = XLSX.utils.sheet_to_json(ws,{header: 1,defval:''})
           console.log(json)

Here excelFile is file location, you may include your excel file location, Then json contain excel data.

Thanks.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.