| 460 | } |
| 461 | |
| 462 | async function readExcelFile(filePath:string) { |
| 463 | const workbook = new ExcelJS.Workbook(); |
| 464 | await workbook.xlsx.readFile(filePath); |
| 465 | |
| 466 | const data:any[] = []; |
| 467 | |
| 468 | workbook.eachSheet((sheet) => { |
| 469 | const headers:string[] = []; |
| 470 | sheet.eachRow((row, rowNumber) => { |
| 471 | // Assume first row is headers |
| 472 | if (rowNumber === 1) { |
| 473 | row.eachCell((cell) => { |
| 474 | headers.push(cell.value as any); |
| 475 | }); |
| 476 | } else { |
| 477 | const rowData = {}; |
| 478 | row.eachCell((cell, colNumber) => { |
| 479 | const header = typeof headers[colNumber - 1] === 'string' ? headers[colNumber - 1] : `Column${colNumber}`; |
| 480 | let value = cell.value; |
| 481 | // if value contains keys text and hyperlink then value becomes hyperlink |
| 482 | // @ts-ignore |
| 483 | if (value && typeof value === 'object' && value.text && value.hyperlink) { |
| 484 | // @ts-ignore |
| 485 | value = value.hyperlink ; |
| 486 | } |
| 487 | // @ts-ignore |
| 488 | rowData[header] = value; |
| 489 | }); |
| 490 | data.push(rowData); |
| 491 | } |
| 492 | }); |
| 493 | }); |
| 494 | return data; |
| 495 | } |
| 496 | async function readExcel(filename: string): Promise<any[]> { |
| 497 | filename = fixExcelFilename(filename) |
| 498 | |