How can I get the count of rows in my uploaded excel

Discussão em 'Angular' iniciado por Learner.123, Fevereiro 27, 2025.

  1. Learner.123

    Learner.123 Guest

    I have uploaded an excel and need to read it and get the count of the number of rows in it.

    I have tried the below codes but it doesn't seen to work out.

    I have been getting so many errors like,"_fs.readFileSync is not a function" "f.slice is not a function" and currently I am stuck at "input.replace is not a function". Please let me know where am I going wrong or what actually needs to be done

    Component.ts

    <pre>

    proceedUpload(){

    if(this.file != null) {


    var workbook = XLSX.read(this.file);


    var firstSheet = workbook.SheetNames[0];


    var excelRows = XLSX.utils.sheet_to_json(workbook.Sheets[firstSheet]);
    var number = excelRows.length();

    if( number > 0 )
    {
    this.uploadMessage = true;
    }
    else
    {
    this.uploadMessage = false;
    }


    let formData: FormData = new FormData();
    formData.append('Files', this.file);

    this.http.post("Url", formData).map(res => res.json())
    .catch(error => Observable.throw(error))
    .subscribe(
    data => console.log('success'),
    error => console.log(error)
    )

    }
    else
    {
    alert("Please upload a file!")
    }
    </pre>


    Component.html

    <div *ngIf="uploadMessage">
    <p>{{number}} uploaded!!</p>
    </div>

    Continue reading...

Compartilhe esta Página