How to read excel file using angular 15 code

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Thanks man! It worked, theres are the steps I made:

Installing the XLSX dependencie
$ npm install XLSX

import the XLSX library on the component I want to use it
import * as XLSX from 'xlsx';

Typescript funtion:

readExcelFile(event: any) {
// Ensure there's a file in the event
if (event.target.files.length === 0) {
console.log("No file selected!");
return;
}

var file = event.target.files[0]; // Get the first file

// Instantiate a new FileReader
const fileReader = new FileReader();

// When file is loaded
fileReader.onload = (e) => {
// Assuming XLSX is properly imported and available
const data = new Uint8Array(fileReader.result as ArrayBuffer);
const workbook = XLSX.read(data, { type: 'array' });
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const headers = ['email', 'name', 'lastName']; // CHANGE this to your actual excel headers!!!!
const excelData = XLSX.utils.sheet_to_json(worksheet, { header: headers });
console.log("Excel File Data", excelData);
};

// Read the file as an ArrayBuffer

}

HTML:
<input type="file"

And it should be console loggin your list of JSONs to work with

jacobo
Автор

Keep doing this great job, I loved this video, thank u so much

Nagidid
welcome to shbcf.ru