-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nir.Tal
authored and
Nir.Tal
committed
Nov 4, 2024
1 parent
ea587c3
commit fe21bec
Showing
2 changed files
with
26 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import xlsx from 'xlsx'; | ||
|
||
/** | ||
* Utility class for file operations | ||
*/ | ||
export class FileUtils { | ||
/** | ||
* Reads data from an Excel file and converts it to a JSON array. | ||
* @param {string} filePath - The path to the Excel file. | ||
* @returns {Promise<{ [key: string]: any }[]>} - A promise that resolves to an array of JSON objects representing the data in the Excel file. | ||
*/ | ||
static async readExcelFile(filePath: string): Promise<{ [key: string]: any }[]> { | ||
const file = xlsx.readFile(filePath); | ||
const data: any[] = []; | ||
const sheets = file.SheetNames; | ||
for (let i = 0; i < sheets.length; i++) { | ||
const sheetData = xlsx.utils.sheet_to_json(file.Sheets[sheets[i]]); | ||
data.push(...sheetData); | ||
} | ||
return data; | ||
} | ||
} |