Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

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

Open
ikochetkov opened this issue Oct 1, 2021 · 0 comments
Open

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

ikochetkov opened this issue Oct 1, 2021 · 0 comments

Comments

@ikochetkov
Copy link

// 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'
    }

}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant