What I’m trying to do:
I’m trying to download data in a excel file. Currently i have data in datatable and also i get data from an api. I’m mergin the data and creating a dictionary. The only way i could download the data is in a .csv format (which is very ugly).
What I’ve tried and what’s not working:
I tried to download the csv file as a excel file but i broke the entire file.
Is there any way to handle excel files in the same way as csv files?
Thank you all
Thanks for your answer @stucork
I’m doing my data manipulation with pandas. But the problem is that i need to download that information in a excel file, in the client side. Currently i can download a .csv file as a BlobMedia file. First a get all the data, then transform to a .csv file and then BlobMedia file. Because i can’t use a excel file as a BlobMedia object, i can’t download it.
Code example:
Then i return that csv_media to the client code and download it using:
csv_media_file= anvil.server.call(‘exportToExcel’) # exportToExcel is my server code function
anvil.media.download(csv_media_file)
I want to do the same BUT with a excel format. Where each value has it’s own column and not all values are in the same column
and on the client side, you might have this in a click hander for a download button:
def download_button_click(self, **event_args):
result = anvil.server.call("export_to_excel", <pass your data and columns here>)
anvil.media.download(result)
I stumbled upon this answer when I was search for pretty much the same question. Is content = io.BytesIO() supposed to include the df dataframe created on the line before?
I pretty much have the same scenario outlined in the OP, where I’m building an excel file on the server end to return to the user. I’m able to create the dataframe, I just can’t seem to get the file written to excel and passed back to the front-end, so this seems like it’s very relevant to that without having to create a new thread.