Uploading, downloading files and equations in text

Can we download excel files those generated by your app in the similar fashion?

Hi @pyuser – Since @Marc’s solution basically uses pandas’ “to_csv” function to do the work, you might try replacing that part of the File Download Workaround with the “to_excel” method documented in the Pandas docs here.

In other words, instead of this line:

csv = df.to_csv(index=False)

You’d put something like this:

xsl = df.to_excel()

I think this will work, or at least this is the stub of a solution. Let us know if you get it working!

Took interest in this topic recently as I’m helping a friend :slightly_smiling_face:

Inspired by @Marc’s example using base64, for .xlsx, and a SO tip, one approach to create the encoding-decoding is as follow:

df = pd.DataFrame(data, columns=["Col1", "Col2", "Col3"])

excel_path = 'test.xlsx'
xlsx = df.to_excel(excel_path)

data = open(excel_path, 'rb').read()
b64 = base64.b64encode(data).decode('UTF-8')

For a full implementation, refer to @Marc’s example.

I suppose one can add drop down to allow user to select output format :slightly_smiling_face:

1 Like

While at it, why add .zip to the list, so one may pack anything into download :slight_smile:

Courtesy of a SO post:

zip_path = "test.zip"
my_zipfile = zipfile.ZipFile(zip_path, mode='w', compression=zipfile.ZIP_DEFLATED)

# Write to zip file
my_zipfile.write(excel_path)

my_zipfile.close()

with open(zip_path, "rb") as f:
    bytes = f.read()
    b64 = base64.b64encode(bytes).decode()

Similar as before, once we get the decoded b64 data, the remaining implementation is covered in @Marc example.

1 Like

how can i download the output of sweetviz and render it in web app

can i give option to download html files and how