The Problem I'm Facing
Currently, I am dealing with a large data table that contains a mix of relevant and irrelevant data. My goal is to filter out the information I care about and display it in a more concise table. Using RegEx, I have managed to identify the indexes of the desired data and store them in a set. Here's a snippet of my approach:
Importing and Processing Excel Data
onFileChange(event: any)
{
const inputFile: DataTransfer = <DataTransfer>(event.target);
const fileReader: FileReader = new FileReader();
fileReader.onload = (event: any) =>
{
const binaryString: string = event.target.result;
const workBook: XLSX.WorkBook = XLSX.read(binaryString, { type: 'binary', sheetStubs: true});
const workSheetName: string = workBook.SheetNames[0];
const workSheet: XLSX.WorkSheet = workBook.Sheets[workSheetName];
this.data = <Array>(XLSX.utils.sheet_to_json(workSheet,
{header: 1, blankrows: true }));
};
fileReader.readAsBinaryString(inputFile.files[0]);
}
Essentially, this function reads an Excel sheet and converts it into an array object, where each array represents a row in the sheet. To further filter the data, I implemented the following function:
columnsWithManufacturer()
{
var someManufacturers = [//list of regex phrases//];
var manColumnIndexes = new Set();
for (var manufacturer of someManufacturers)
{
for (const row of this.data)
{
for (var cell=0; cell< row.length; cell++)
{
if (manufacturer.test(row[cell]))
{
manColumnIndexes.add(cell)
}
}
}
}
return manColumnIndexes
}
Here, 'cell' represents the column value in the Excel sheet where the data is located, and the set 'manColumnIndexes' holds unique column numbers where relevant data is found. My objective now is to segregate this data into separate arrays based on the column numbers. For example, data from columns 14, 16, and 17 should be stored in separate arrays using a distinct function.
My Approach and its Flaw
In an attempt to achieve this, I created a new function as follows:
pushIntoSeparateArrays()
{
var manufacturersArrays = [this.primaryManufactArray,this.altManufactArr,this.altManufactArr2,this.altManufactArr3]
var manufactIndexes = this.columnsWithManufacturer()
for (var array of manufacturersArrays)
{
for (var row in this.data)
{
manufactIndexes.forEach((value) =>
{
array.push(this.data[row][Number(value)])
})
}
}
}
However, as I've realized, this approach ends up pushing all the data from all column values into all arrays. There seems to be a missing step in my process. Can you assist me in properly separating the data into distinct arrays as intended?