resolucion de errores

This commit is contained in:
evenegas
2026-07-29 11:30:14 -06:00
parent cbdcd0ca1e
commit 648e980fa8
2 changed files with 36 additions and 36 deletions
+27 -27
View File
@@ -4,42 +4,42 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class ExcelService {
async readEmailsFromExcel(file: Express.Multer.File) {
// 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 workbook = new ExcelJS.Workbook();
// await workbook.xlsx.load(file.buffer); // 🔹 `await` para leer el archivo correctamente
const rowData = {
Correo: row.getCell(1).value, // Ajusta el índice según tu archivo
};
// const worksheet = workbook.getWorksheet(1); // Obtiene la primera hoja
// if (!worksheet) {
// throw new Error(' No se encontró ninguna hoja en el archivo.');
// }
jsonData.push(rowData);
});
// const jsonData: any[] = [];
console.log(` Datos extraídos:`, jsonData);
// // 🔹 Iterar sobre las filas y extraer datos
// worksheet.eachRow((row, rowNumber) => {
// if (rowNumber === 1) return; // Ignorar encabezado
// 🔹 Extraer correos de la columna "Correo"
const emails = jsonData
.map(row => row.Correo)
.filter(email => typeof email === 'string');
// const rowData = {
// Correo: row.getCell(1).value, // Ajusta el índice según tu archivo
// };
console.log(` Correos extraídos:`, emails);
// jsonData.push(rowData);
// });
return emails;
}
// 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;
// }
}