I
I
Ilya Bobkov2019-02-06 06:30:24
JavaScript
Ilya Bobkov, 2019-02-06 06:30:24

What encoding to save excel data in?

Greetings!
There is a RestAPI that provides excel (xlsx) data as a request:

request.post( 
     rest_url+"/basecoefficient/getReport", { json: true, body: req.body.data, headers: { 
    'content-type' : "application/json; charset=utf-8",   'Authorization': "Bearer " + req.body.token } }
    , function(err, response, body)  {

    console.log(response.body)
    return res.json(response)

  });

Response.body receives excel data (xlsx) in UTF form:
PK\u0003\u0004\u0014\u0000\b\b\b\u0000\u000b�DN\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000b\u0000\u0000\u0000_rels/.rels���j�0\f�_���8�`�Q��2�m��\u00014[ILb��ږ���.[K\n\u001b�($}�\u0007�v?�I�Q.���uӂ�h���\u001bx>=��@\u0015��p�H\u00

When saving data in the current format, the file does not open. the data is in UTF format. How to convert UTF encoding to excel (xlsx) recognizable format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2019-02-06
@DarkRaven

Apparently, you process binary data as json.
I would reconsider in principle downloading the report - I would not return data, but would return a link where you can download the file.
In general terms, your POST request builds an excel and saves it to the file system. The output is a link to it, it is given to the client.
The client follows the link (the redirect is the same, for example), the file is downloaded and deleted from the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question