Тёмный
No video :(

Fetch Data from Excel File in React JS | React XLSX 

WebStylePress
Подписаться 17 тыс.
Просмотров 29 тыс.
50% 1

Fetch data from an Excel file in a React JS application. We will install required dependencies. Import the dependencies. Read the Excel file. Parse the data and save it in a state. Display the data from the state in the component.
The task requires xlsx library for parsing the Excel file. Install the dependencies using npm or yarn. Open terminal in project and use command npm install xlsx. After dependency is installed. Import the dependencies like useState hook and xlsx. Import all the exported members from the 'xlsx' library and make them available as an object 'XLSX'. Define a state called data and a function setData to update the state. Initialize this state with an initial value of an empty array. Create an input element of type "file" that allows user to choose an excel file from local file system. This file field will trigger the handleFileUpload function to process the file when a new file is selected. Create a function to read and parse the Excel file.
HandleFileUpload takes an event object e as its argument. This event object is automatically passed by the browser when the onChange event is triggered on the file input element. Create a new instance of the FileReader class. It provides methods to read the content of provided file. The readAsBinaryString method is called on the reader object to start reading the content of the uploaded file.
The files property of the event object e.target holds the list of files, and the first file is passed to the method. Once the file's content is read, the onload event is triggered, and the callback function is executed. Assign an event listener to the onload property of the reader object. This event listener is a callback function that is executed when the FileReader has successfully read the file's content. Pass the event object e, to the onload callback function, that contains result property. Result property holds the contents of the file as a binary string. This content is assigned to the data variable here.
The read function from the xlsx library is used to parse the 'binary string data' and create a workbook object representing the Excel file. The first sheet's name is being extracted from the workbook object by accessing the SheetNames array. If you need to fetch data from different sheet, you can change the number here. The first sheet's actual data is being obtained from the workbook object by using the extracted sheet name as the key.
The sheet to json function is used to convert the first sheet's data into a JSON object. This JSON object is an array of row objects, with each object representing a row in the sheet. Call the setData function to update the state variable data with the parsed JSON data. Now we have the data in state.
Apply a check that checks if data is not empty. Create table adn use map method to get the keys and values separately to display data from excel file. Now, when you upload an Excel file, the data will be displayed in a table. This is how we can display data from an Excel file in React JS.
Get the Code:
github.com/web...
- Fetch Data from CSV File in React JS | React CSV
• Fetch Data from CSV Fi...
- Fetch Data from JSON File in React JS | React JSON [ UPDATED ]
• Fetch Data from JSON F...
- 7 Ways to use Images in React JS
• 7 Ways to Use Images i...
- Easy Way to use Images in React JS | No Import | No Require
• Easy Way to Use Images...
- Require Image Not Working in React JS
• Require Image Not Work...
- Multiple Images in One Import
• Multiple Images in ONE...
- Multiple Sets of Images from One Import in React JS
• Multiple Sets of Image...
- Display Records or Data from JSON File in React JS
• Display Records or Dat...
- Default Map is not a Function in React JS
• Default MAP is Not a F...
- Async Await Fetch in React JS
• Multiple Ways of Async...
- ReactJS Playground
• ReactJS Playground
Our tutorials help you to improve your career growth, perform better in your job and make money online as a freelancer. Learn the skills to build and design professional websites, and create dynamic and interactive web applications using JavaScript, or WordPress. Our tutorials are tailored to help beginners and professionals alike. Whether you're just starting in the field or you're looking to expand your knowledge, we've got something for you. Join us on this journey to becoming a skilled web developer. Subscribe to our channel and let's get started!
Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT
⚡Channel: / @webstylepress
⚡Website: www.webstylepr...
⚡FaceBook: / webstylepress
⚡Twitter: / webstylepress
⚡GitHub: github.com/web...
#react #reactjs #js #WebStylePress #javascript #xlsx #xls #sheets #excel

Опубликовано:

 

25 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 10   
@webstylepress
@webstylepress 10 месяцев назад
If you want to fetch single column from excel file, here is the tutorial ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-M_B5Td7ZoEY.html
@pratikdubey5319
@pratikdubey5319 18 дней назад
What if we just wanted to select just a single shell then what we can do? Please help Sir
@danielacurielgomez6687
@danielacurielgomez6687 13 дней назад
thanks! it was exactly what I needed 👻
@driyagon
@driyagon Год назад
helpful video!
@kevyyar
@kevyyar Год назад
What if there is a complex excel structure? I'm this example the headers are on the first row. But what if there some headers/titles in other parts of the excel?
@user-zm5rz1qg9c
@user-zm5rz1qg9c 9 месяцев назад
if there are multiple sheets?
@mocambiquemaputomatola8238
@mocambiquemaputomatola8238 6 месяцев назад
Hello, can you help me? I intend to develop an academic management system using Next.js 14, and I want to know how I can update students' grades using an Excel file that contains the grades for all assessments and the corresponding student numbers for each grade. Considering that each student accesses the system using their student number as a username and a password to access the student area, and all information has to be stored in the PostgreSQL database management system, I have a question: can I use PostgreSQL from Vercel or Supabase?
@duncankioi9437
@duncankioi9437 10 месяцев назад
Hello, And If you only want to access data from only one column...How do you do that?
@webstylepress
@webstylepress 10 месяцев назад
Tutorial uploaded for you. There you go. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-M_B5Td7ZoEY.html
@robin3111
@robin3111 3 месяца назад
I am getting error as : [eslint] src\App.1.js Line 12:23: Parsing error: Unexpected token (12:23) even though all syntax is correct :( anyone can help pls ?
Далее
Fetch Data from CSV File in React JS | React CSV
11:24
HOW DID SHE DECIDE TO DO THIS?!
00:27
Просмотров 5 млн
Render pdf, docx, xlsx, ppt etc. in react application
12:35
Next.js Reports tutorial with Microsoft Excel
18:19
Просмотров 14 тыс.
Upload and View Excel Files In React
10:37
Просмотров 22 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 354 тыс.
Google Sheets… Your Next Database?
7:16
Просмотров 392 тыс.
REACT -  Read & Parse Excel Sheets with SheetJS
12:29
Просмотров 24 тыс.