Replies: 14 comments
-
@resobyte, did you fix this yet, i am facing a similar issue, my environment is node js |
Beta Was this translation helpful? Give feedback.
-
Hi @aksharj, React.js
Node.js
You can fix this code. I used axios and fileSaver. You can use GET method. Important: responseType :'arrayBuffer' |
Beta Was this translation helpful? Give feedback.
-
hi @resobyte, thanks for sharing the solution. Does this work with large files, if i understand correctly, you are loading the entire contents of the file in memory. |
Beta Was this translation helpful? Give feedback.
-
Hi @aksharj, I didn't try large files. My excel file 30KB. If you try, can you give me information too.. Thanks. |
Beta Was this translation helpful? Give feedback.
-
@resobyte if(linkRef.current){
const linkSource = `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,${data.productsReport}`;
const downloadLink = linkRef.current;
const fileName = `${reportName}.xlsx`;
downloadLink.download= fileName;
downloadLink.href = linkSource;
downloadLink.target = '_blank';
downloadLink.click();
} Create an on Back End const buffer = await workbook.xlsx.writeBuffer() as unknown as Buffer;
return buffer.toString('base64'); Note that casting to unknown is needed because the Don't hesitate to reach me if you have any questions |
Beta Was this translation helpful? Give feedback.
-
After some tests I came to a conclusion. On my backend: const buffer = (await workbook.xlsx.writeBuffer()) as Buffer;
response.write(buffer);
response.end(); On my front-end: axios.get(`myRoute`, { responseType: 'arraybuffer' })
.then(response => {
const blob = new Blob([response.data], {
type:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});
FileDownload(blob, `file.xlsx`); // npm " js-file-download" responsible for downloading the file for the user
}); |
Beta Was this translation helpful? Give feedback.
-
You can do this by fetch API.
|
Beta Was this translation helpful? Give feedback.
-
FileDownload Not found function |
Beta Was this translation helpful? Give feedback.
-
Are you sure you are using "import FileDownload from 'js-file-download';"? |
Beta Was this translation helpful? Give feedback.
-
what am I missing? |
Beta Was this translation helpful? Give feedback.
-
This looks like a buffer to me. Show me your code. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer. Node:
Frontend:
|
Beta Was this translation helpful? Give feedback.
-
.then((response) => { I used it but the file does not open |
Beta Was this translation helpful? Give feedback.
-
Any one fo this for post method?? |
Beta Was this translation helpful? Give feedback.
-
💬 Questions and Help
Hi everyone,
I have two separate projects. Client: React, Server: NodeJS
I create excel on the NodeJS side by submitting a form by React.
I want to download this excel from React side. However, I couldn't download it.
NodeJS code
NodeJS return network layer
First try React.js code
Second try React.js code
The file has been downloaded.
My React Service Call
Error open excel file
Please do not originate issue 37. Because I tried all of them don't work.
Beta Was this translation helpful? Give feedback.
All reactions