diff --git a/src/app/components/book/book-excel-parser/book-excel-parser.component.html b/src/app/components/book/book-excel-parser/book-excel-parser.component.html
index 8332f13..67ba004 100644
--- a/src/app/components/book/book-excel-parser/book-excel-parser.component.html
+++ b/src/app/components/book/book-excel-parser/book-excel-parser.component.html
@@ -6,25 +6,39 @@
Instructions
- 1. This importer allows you to choose an excel file, see all the values of it in a table and then import those books into the database.
+ This importer allows you to choose an excel file, see all the values of it in a table and then import those books into the database.
- 2. Currently supported extensions:.
+ The importer assigns each value of a row depending on the column header. As a consequence the first row of the excel file must contain the following values:
+
+
+ - Title
+ - ISBN
+ - Active
+ - Price
+ - Stock
+ - Genre
+ - Author
+ - Format
+
+
Reminder
+
+ 1. Currently supported extensions:.
- 3. All new genres used in the excel will be created.
+ 2. All new genres used in the excel will be created.
- 4. All new formats used in the excel will be created.
+ 3. All new formats used in the excel will be created.
- 5. Books are identified by their ISBN. This has the following consequences:
+ 4. Books are
identified by their ISBN. This has the following consequences:
- - If the ISBN is not assigned yet, the book will be added.
- - If the ISBN is already assigned, the book will be updated.
+ - If the ISBN is not assigned yet, a new book will be added.
+ - If the ISBN is already assigned, the existing book will be updated.
diff --git a/src/app/components/book/book-excel-parser/book-excel-parser.component.ts b/src/app/components/book/book-excel-parser/book-excel-parser.component.ts
index 06b4241..4ffabc8 100644
--- a/src/app/components/book/book-excel-parser/book-excel-parser.component.ts
+++ b/src/app/components/book/book-excel-parser/book-excel-parser.component.ts
@@ -44,6 +44,8 @@ export class BookExcelParserComponent implements AfterViewInit{
protected parsedData: Book[] = [];
+ protected fileReader = new FileReader();
+
/**
* Constructor
* @param {BookService} service - The BookService for handling book-related operations.
@@ -108,22 +110,16 @@ export class BookExcelParserComponent implements AfterViewInit{
const file = event.target.files[0];
if(file && requiredFileType(file, allowedParserExtensions)){
- let fileReader = new FileReader();
-
this.isLoading = true;
- fileReader.readAsBinaryString(file);
+ this.fileReader.readAsBinaryString(file);
- fileReader.onload = (e) => {
+ this.fileReader.onload = (e) => {
this.parsedData = [];
this.excelSelected = true;
- const workBook = XLSX.read(fileReader.result, {type:'binary'});
-
- const sheetNames = workBook.SheetNames;
-
- this.data = XLSX.utils.sheet_to_json(workBook.Sheets[sheetNames[0]]);
+ this.readExcelWorkBook();
this.dataSource.data = this.data;
@@ -141,6 +137,22 @@ export class BookExcelParserComponent implements AfterViewInit{
}
}
+ /**
+ * Reads an Excel workbook and extracts data from all its sheets into a single array.
+ * This method is useful for processing Excel files in web applications where data from multiple sheets needs to be combined or displayed together.
+ */
+ private readExcelWorkBook() {
+ const workBook = XLSX.read(this.fileReader.result, {type:'binary'});
+
+ const sheetNames = workBook.SheetNames;
+
+ for (let index = 0; index < sheetNames.length; index++) {
+ const sheetName = sheetNames[index];
+ const sheet = workBook.Sheets[sheetName]
+ this.data = this.data.concat(XLSX.utils.sheet_to_json(sheet));
+ }
+ }
+
/**
* Parses each Excel book entry into a Book and populates the parsedData array.
*/