My current task involves importing an Excel File in the following manner:
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});
/* sheetstubs true supposedly shows empty cells but isn't */
console.log(typeof binaryString)
const workSheetName: string = workBook.SheetNames[0];
console.log(workSheetName)
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]);
}
My goal is to identify the index (essentially the column number) of any cell that contains the word 'cap' using regex.
I attempted to use regex as shown below to search for the term cap
in any cell but encountered the following error,
Argument of type 'RegExp' is not assignable to parameter of type 'string'.
I am puzzled by the meaning of this error message and unsure how to proceed.
getManufacturerDescriptionColumn()
{
for (const row in this.data)
{
var descIndex = row.indexOf(/cap*/i)
return descIndex
}
}