Q:

Writing data into excel file with node js

I created a Rest API with the express framework that contains a route for exporting data. The data that should be exported to an excel file is stored in multiple arrays. The excel file should have a predefined structure/styling.
I am not limited to a certain file format as long as it can be opened in Microsoft Excel. Is there any recommendation which to use?
In general, how do i achieve this goal. Do i have to map each entry of the arrays to a certain cell in the excel file? How can i style/format a excel file with node js?
Please give me some general understanding of how to approach this task. I am very thankful for your help!
Edit:
I found the node module excel4node. Is it suitable for this task or are there better soultions?

A:

Excel4Node is pretty nice, I've found this to be very useful for creating Excel documents, the API is very flexible, it's easy to write objects / arrays to a file, style it and save.
Styling is very simple, you can create Style objects and apply them to cells, again this is very flexible.
For example: 
const excel = require("excel4node");

const workbook = new excel.Workbook();

const style = workbook.createStyle({
    font: { color: "#0101FF", size: 11 }
});

const worksheet = workbook.addWorksheet("Sheet 1");

const arrayToWrite = Array.from({length: 10}, (v, k) => [`Row ${k+1}, Col 1`,`Row ${k+1}, Col 2`]);
arrayToWrite.forEach((row, rowIndex) => {
    row.forEach((entry, colIndex) => { 
        worksheet.cell(rowIndex + 1, colIndex + 1).string(entry).style(style); 
    })
})

workbook.write("text.xlsx");

There is also Xlsx, though I find this more useful for parsing than for file creation. It will also work in a browser.
To create a spreadsheet in memory, then allow the client to download: 
const express = require("express");
const port = 8000;
const app = express();
const stream = require("stream");
const excel = require("excel4node");

function createTestWorkbook() {
    const workbook = new excel.Workbook();
    const style = workbook.createStyle({
        font: { color: "#0101FF", size: 11 }
    });

    const worksheet = workbook.addWorksheet("Sheet 1");

    const arrayToWrite = Array.from({length: 10}, (v, k) => [`Row ${k+1}, Col 1`,`Row ${k+1}, Col 2`]);
    arrayToWrite.forEach((row, rowIndex) => {
        row.forEach((entry, colIndex) => { 
            worksheet.cell(rowIndex + 1, colIndex + 1).string(entry).style(style); 
        })
    })

    return workbook;
}

/* Allow client to download spreadsheet. */
app.get('/get-spreadsheet', (req, res) => {
    let workbook = createTestWorkbook();
    workbook.write('workbook.xlsx', res);
});

app.listen(port);
console.log(`Serving at http://localhost:${port}`);

This requires you to do 
npm install express

Then run the script and goto http://localhost:8000/get-spreadsheet/

