简体   繁体   中英

How to convert a excel file to base64 and then convert base64 back to excel in python?

How to convert a excel file to base64 and then convert base64 back to excel in python? I intent to store the Base64 data in a database and retrieve it on demand and convert back to excel? Any help?

import base64

def open_target_file(target_path):
    with open(target_path,"rb") as excel_file:
        return excel_file.read()

def encode_file(excel_file):
    return base64.b64encode(excel_file)

def decode_file():
    return base64.b64decode(excel_file)

your_excel_path = ""
destiny_path = ""

excel_file = open_target_file()
encoded_excel = encode_file(excel_file)
decoded_excel = decode_file(encoded_excel)

with open(destiny_path, "wb") as decoded_file:
    decoded_file.write(decoded_excel)

Somthing like this should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM