'How to create 250MB to 750 MBs xlsx file in JavaScript?

I'm trying to create a XLSX file from json, but when I'm trying this code:

const convertJsonToExcel = () => {
    

    //var objeto=JSON.parse(JSON.stringify(jsonData))
    console.log(typeof(bigJson))

    const workSheet = XLSX.utils.json_to_sheet(bigJson['titulo']);
    const workBook = XLSX.utils.book_new();

    XLSX.utils.book_append_sheet(workBook, workSheet, "students")
    // Generate buffer
    XLSX.write(workBook, { bookType: 'xlsx', type: "buffer" })

    // Binary string
    XLSX.write(workBook, { bookType: "xlsx", type: "binary" })

    XLSX.writeFile(workBook, "studentsData.xlsx")
}

I get: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

This json file is 132MBs, but I'll have files until 250MBs. I looked for ExcelJS library, but it has some issues too : https://github.com/exceljs/exceljs/issues/709

What would be a good strategy?

EDIT:

const convertJsonToExcel = () => {

var arr=bigJson['titulo']

// arr2=arr.slice(arr.length/2, arr.length-1)
// arr=arr.slice(0, arr.length/2)
// arr3=arr.slice(0, 1)

console.log(typeof(bigJson))

const workSheet = XLSX.utils.json_to_sheet(arr);

//XLSX.utils.sheet_add_json(workSheet,arr2,{origin: -1});

const workBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workBook, workSheet, "students")
XLSX.writeFile(workBook, "studentsData.xlsx")
}

I was trying to create a xlsx file from a json of 500MBs, but it only keeps working without response. This works for 250MBs file.

I tried with the commented part dividing in two blocks the json file, and not getting response again



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source