Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
XLSX to CSV file convert for API call

Im trying to convert .xlsx file to .csv file before i send it to the API (because it accepts only .csv files) ;

I am using package xlsx and i got this function that converts it for me but problem is that this function will make the user download the file, and i don't want that i just want that it saves it kinda in like a object so i can use it only for the api (and don't let know the user that its converted ).

Here is code:

    file.arrayBuffer().then(res => {
            let data = new Uint8Array(res)
            let workbook = XLSX.read(data, {type: "array"})
            let first_sheet_name = workbook.SheetNames[0]
            let worksheet = workbook.Sheets[first_sheet_name]
            let jsonData = XLSX.utils.sheet_to_json(worksheet, {raw: false, defval: null})
            let fileName;
            if (file) {
                fileName = file?.name.substring(0, file?.name?.indexOf("."))
            }
            let new_worksheet = XLSX.utils.json_to_sheet(jsonData);
            let new_workbook = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(new_workbook, new_worksheet, "csv_sheet")

            getRandomRows(jsonData)
            XLSX.writeFile(new_workbook, fileName + ".csv")
            
        })

Was wondering if there are other options too.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I fixed it this way :

        let dataToSheet = XLSX.utils.json_to_sheet(data)
        const dataFileCSV = XLSX.utils.sheet_to_csv(dataToSheet, {raw: false, defval: null});
        let blob = new Blob(["\ufeff", dataFileCSV]);
        let fileBlob = new File([blob], "name");

about 4 years ago · Juan Pablo Isaza Report

0

Based on Readme from xlsx try to use writeFileAsync or just write instead of writeFile as it force browser to start download

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!