Argument of type 'RegExp' is not assignable to parameter of type 'string'

Discussão em 'Angular' iniciado por Banani720, Novembro 14, 2024.

  1. Banani720

    Banani720 Guest

    I am trying to import an Excel File like so:

    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]);

    }


    and want to find the index (basically the column number) of any cell that contains the phrase 'cap' in it using regex.

    I am trying to use regex like so below to search for the term cap in any of the cell but am met with the following error,

    Argument of type 'RegExp' is not assignable to parameter of type 'string'. I am unclear as to what this error is trying to indicate to me and what might be a good way to achieve what I am trying to achieve.

    getManufacturerDescriptionColumn()
    {
    for (const row in this.data)
    {
    var descIndex = row.indexOf(/cap*/i)
    return descIndex
    }
    }

    Continue reading...

Compartilhe esta Página