MCPcopy Index your code
hub / github.com/omkarcloud/botasaurus / readExcelFile

Function readExcelFile

js/botasaurus-js/src/output.ts:462–495  ·  view source on GitHub ↗
(filePath:string)

Source from the content-addressed store, hash-verified

460}
461
462async 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}
496async function readExcel(filename: string): Promise<any[]> {
497 filename = fixExcelFilename(filename)
498

Callers 1

readExcelFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected