deepfos.lib.sysutils.export_file_for_download¶
- deepfos.lib.sysutils.export_file_for_download(file_name, file)¶
导出文件至下载中心
如下几种用法皆可
from deepfos.lib.sysutils import export_file_for_download # . 直接提供文件内容字符串 export_file_for_download('t1.txt', 'ttttt') # . 提供包含内容的文件 with open('t.txt', 'r') as fp: export_file_for_download('t2.txt', fp) # . 提供包含内容的文件的bytes with open('t.txt', 'rb') as fp: export_file_for_download('t3.txt', fp.read()) # . 提供buffer import io import pandas as pd buffer = io.BytesIO() # 将dataframe内容写入buffer with pd.ExcelWriter(buffer, engine="openpyxl") as writer: pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}).to_excel( writer, index=False, encoding='utf-8' ) # 上传至下载中心 export_file_for_download('out.xlsx', buffer.getbuffer())