Reputation: 43
When i try to make a get request with Axios on a .xslx file, i get some special characters (maybe it's binary? I don't know) on my console.
it looks like this:
�V�?x�(~�O!�OXȽGG��x��ӫ��+j��&����Z�֗_��
�v�z��˦�5b?i3�E�k�f{���2�⠌>�%���W
D�DNb���)�B0�d����j�n����m-E_>�*w�@<�=�=Ld=F�-�ɉ`�Ⱦ�y:��]�qÃra:�N�,Τ�f�Xk��`�/RW�-��mI��Ȋ!ɠ����wI���fR!���C��@l�6��/���
Œ�鐾���R���+C%P�54T`Q���݉�O}6����d�ת���k��!gU-d!��x�yyi�HN�c�� �"�'ы$%�0a�?w4�P���Ⱥ�eA��NJS|j�·kJl;�8����]��t�W3��qz��O�
ߔ!xl�+�Q�z���Qi��4=1\]�;��gT^���Zg�^��U��!|n1�qc��suX11�Uuj��ThO:7>0���!����.
�<���[i�*��l���
J%.�>�ٹZ��=���.l�`|jv.��geb���ecq���>C�*�
�3N�?� �&����r��t���2�إ�
2C�V�M�R�R�<[zRO�0߬����f� �����w�(�����z���{�8�P�����Ϧ�V�qn�vqK
'1���i��f)k��D*QmQ�B�Z��ػ�&����O�����3����&�OdsEa�FP��:e_⺽��k��x��'�(�_��<���{��¬���8�������%OYu˃�<��҆���Z�_��l�y�F�:�:]�|��Qb�]d>��+ϴ�Z10O��*ݐ'�}���3g�R.��yth�˘��d��Tܼ)�!�U�ӀQ[���KsX�#)�O+��zĭZ���9l�k�M��h�Xݯ�=���$��C���)�#w]�J�r�������;5
��Gt������������P5¯߳{�Y�[����$�.��^N����ܰ~�̲�]�b��o���v�xhs�ɼN��v��h����1}��P'���Ez>ᣍiԯ�fq�����ޗ�r7���uB�n�����d�=�vTUs�{�%XB�����M�i��{�\J���+���F�JH
�1�<ב0[�ټ�{��_��b�t��H�i�E�ols���%I���k���d1�>
��-xdn;�1S�cl������]m0
��� ��!�v/�e�:갮����x��3�h�A
�B�U$rW��-)��Z�C�K�}l5O����C�7E��G�]e猆�߲Hv��_t-�g�)
���o�?��G�J,Z�7�o�ٗ�qN
��v��&eb��B��KT���&���^��K�<{��֦�xмW�.4��
<��<" �o��Pl�,N`Mn]�?d[rv��n&;Y>�5p��Y Y���Jr�*M�$����E�R���M���?��7wby�� � p�� � � �/��P!S���� xl/calcChain.xmlt�݊�0��}�0�kڪ��4텬O�>@HǶ���ѷw`Q�5��㜜�i��5�!N�I(�0t�����[`1)�+�J�`���X4Z��5�(aLi��<���K?�#r���D�0�8T}�5�*���IB���P�}�D���R�e����U�s�n�2W��E�\���?s~?b{��P!�����docProps/core.xml �(�|�]o� ��'�? ��
p>� Ǒ�)��*U��V�#�&a3`[�?�>hg��(F`�S�n�[��
�BV��YX���>~(e˥�p�]
>(�l�]�]�-'$�FIa�q�1}�-i��)�@rJg�@JDA:`֞�x@*yF��|��$Ѐ#F^�� ��˅��xhS�!�%[���~ �,���������3�|�����i�m%W��\z����n4��4#xtޮ�AW��SI.tݦ�.ͿѠn�h@��B�j�������WB�{m���)+2F3:���s>�/��;�R�~�c���T��9]�Ʒ���x�MȢf9�Nx�+������H����8�\O���������PK!`�z��
[Content_Types].xmlPK!�U0#�L
�_rels/.relsPK!�i�W
I have tried some different responseType settings, but it gives me the same output. I have also tried to change the responseEncoding, but still no change in the output.
This is my axios call - all plain and simple. As i said, i have tried with responseType settings and responseEncoding... (the URL is private thats why it just says link.xlsx).
app.get("/pep", async (req, res) => {
try {
const pepList = await axios({
url:
"link.xlsx?la=da"
});
console.log(pepList.data);
Do you know how to get some data from this that i can use? I need to be able to get the xlsx data to XML data?
Thanks 😃
Upvotes: 4
Views: 2076
Reputation: 30715
I'd suggest parsing the downloaded .xlsx file using the xlsx module, this allows you to convert worksheets to json. This can then be converted to xml using jsontoxml.
Using an example online .xlsx file:
const axios = require("axios");
const XLSX = require("xlsx");
const jsontoxml = require("jsontoxml");
async function testAxiosXlsx(url) {
const options = {
url,
responseType: "arraybuffer"
}
let axiosResponse = await axios(options);
const workbook = XLSX.read(axiosResponse.data);
let worksheets = workbook.SheetNames.map(sheetName => {
return { sheetName, data: XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]) };
});
console.log("json:\n", JSON.stringify(worksheets), "\n\n");
console.log("xml:\n", jsontoxml(worksheets, {}));
}
testAxiosXlsx("https://file-examples.com/wp-content/uploads/2017/02/file_example_XLSX_10.xlsx");
This will log the .xlsx file as xml data, it'll look something like this:
<sheetName>Sheet1</sheetName>
<data>
<0>1</0>
<First Name>Dulce</First Name>
<Last Name>Abril</Last Name>
<Gender>Female</Gender>
<Country>United States</Country>
<Age>32</Age>
<Date>15/10/2017</Date>
<Id>1562</Id>
</data>
Upvotes: 5