46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import * as fs from 'fs';
|
|
import * as ExcelJS from 'exceljs';
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
@Injectable()
|
|
export class ExcelService {
|
|
// async readEmailsFromExcel(file: Express.Multer.File) {
|
|
|
|
|
|
|
|
|
|
|
|
// const workbook = new ExcelJS.Workbook();
|
|
// await workbook.xlsx.load(file.buffer); // 🔹 `await` para leer el archivo correctamente
|
|
|
|
// const worksheet = workbook.getWorksheet(1); // Obtiene la primera hoja
|
|
// if (!worksheet) {
|
|
// throw new Error(' No se encontró ninguna hoja en el archivo.');
|
|
// }
|
|
|
|
// const jsonData: any[] = [];
|
|
|
|
// // 🔹 Iterar sobre las filas y extraer datos
|
|
// worksheet.eachRow((row, rowNumber) => {
|
|
// if (rowNumber === 1) return; // Ignorar encabezado
|
|
|
|
// const rowData = {
|
|
// Correo: row.getCell(1).value, // Ajusta el índice según tu archivo
|
|
// };
|
|
|
|
// jsonData.push(rowData);
|
|
// });
|
|
|
|
// console.log(` Datos extraídos:`, jsonData);
|
|
|
|
// // 🔹 Extraer correos de la columna "Correo"
|
|
// const emails = jsonData
|
|
// .map(row => row.Correo)
|
|
// .filter(email => typeof email === 'string');
|
|
|
|
// console.log(` Correos extraídos:`, emails);
|
|
|
|
// return emails;
|
|
// }
|
|
}
|