How to include a .docx and .xlsx download file on the page?

How would I go about adding pre-formatted word and excel documents as downloads on my app? It seems that all the methods out there right now are CSV focused and do not allow the download of more complex data types. When I have tried to added something more like:

html.A("Download Excel Template", href=r"download/Template.xlsx", download=r"download/Template.xlsx")

I only receive corrupt files.

If you are not creating it dynamically, then it shouldn’t be any difference. I couldn’t say for sure why you are having the corrupt files (a more complete example would help), but I think that using the a assets folder instead of download would do the trick. I just tried this out myself and it worked fine. I also didn’t include any download argument in the the html.A, just the href.

1 Like

huh, weird. I just added the files to the assets folder instead of its own folder and it worked. Not sure why that was necessary, but I’ll take it!

Great! Glad it worked out.

assets is setup as the default folder that the underlying flask instance uses for serving static files. I believe the download folder you referenced has to do with a community post that uses a flask route to create a dynamic file on the back-end.

If you are interested in how to change that folder name, or to simply learn more about that, then check out the source here:

1 Like

Hi @WolVes ,

can you give me an example code of how that download would look like with the app layout and callback? I also need to have a template excel file available to download on my app, but don’t know how to do that.