natergj / excel4node

Node module to allow for easy Excel file creation
MIT License
1.38k stars 215 forks source link

Get the binary code of excel and return it without express.js #349

Open ikochetkov opened 3 years ago

ikochetkov commented 3 years ago
// sends Excel file to web client requesting the / route
// server will respond with 500 error if excel workbook cannot be generated
var express = require('express');
var app = express();
app.get('/', function(req, res) {
  wb.write('ExcelFile.xlsx', res);
});
app.listen(3000, function() {
  console.log('Example app listening on port 3000!');
});

Hi folks I'm using Azure container and It's not allow to use the express.js library, it's using some other vanilla methods and response can be returned only trough

context.res={
body: 'test'
}

So I'm not able to use this method wb.write('ExcelFile.xlsx', res);, because I don't have a RES. Tried context.res but it's also not working

Is there a way how can I get the binary data and put it to some variable and then put it into context.res={body:'test'} manually?

For example this code works and returns 'test' to me, but I'm not able to return binary data.

module.exports = async function (context, req) {
    // Require library
    var xl = require('excel4node');

    var wb = new xl.Workbook();
    var ws = wb.addWorksheet('S');
    ws.cell(1, 1).string('A');
    wb.write(`FileName.xlsx`, context.res);
    context.res={
        body: 'test'
    }

}