Migrando xlsx a exceljs
This commit is contained in:
@@ -16,7 +16,6 @@ import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { EmailDto } from './dto/emailDto.dto';
|
||||
import { EmailService } from './email.service';
|
||||
import { Response } from 'express';
|
||||
import * as xlsx from 'xlsx';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Controller('email')
|
||||
|
||||
@@ -13,7 +13,6 @@ import { EventosService } from 'src/eventos/eventos.service';
|
||||
import { Participante } from 'src/participante/participante.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { EmailDto } from './dto/emailDto.dto';
|
||||
import * as xlsx from 'xlsx';
|
||||
import * as pdfMake from 'pdfmake/build/pdfmake';
|
||||
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
|
||||
/* import * as PDFDocument from 'pdfkit'; */
|
||||
@@ -127,9 +126,25 @@ export class EmailService {
|
||||
//traemos la info del evento
|
||||
const evento = await this.eventoService.getEventosPorId(id_evento);
|
||||
|
||||
const workbook = xlsx.read(file.buffer);
|
||||
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
|
||||
const data = xlsx.utils.sheet_to_json(worksheet);
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
await workbook.xlsx.load(file.buffer);
|
||||
const worksheet = workbook.worksheets[0];
|
||||
|
||||
const data: any[] = [];
|
||||
let headers: string[] = [];
|
||||
worksheet.eachRow((row, rowNumber) => {
|
||||
const rowData: any = {};
|
||||
row.eachCell({ includeEmpty: true }, (cell, colNumber) => {
|
||||
if (rowNumber === 1) {
|
||||
headers[colNumber] = String(cell.value).trim();
|
||||
} else {
|
||||
rowData[headers[colNumber]] = cell.value;
|
||||
}
|
||||
});
|
||||
if (rowNumber > 1) {
|
||||
data.push(rowData);
|
||||
}
|
||||
});
|
||||
|
||||
// Carga el PDF pre-diseñado
|
||||
const existingPdfBytes = fs.readFileSync('src/email/DisenoConstancia.pdf');
|
||||
|
||||
Reference in New Issue
Block a user