简体   繁体   English

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?

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?我打算将 Base64 数据存储在数据库中并按需检索并转换回 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.像这样的东西应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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