PANDAS 에서 EXCEL 파일 익스포트





csv


import base4
from io import BytesIO

data = setDATA // pandas

fileName =. 'ccc.csv'

file = data.to_csv( index=False )
b64 = base64.baseencode( file.encode().decode()  )
href = f'<a href="data:file/csv:base64,{b64}". download="{fileName}">{linkName}</a>' 


excel


output = BytesIO()
writer = pd.ExcelWriter( output, engine='xlsxwriter' )

pandasDATA.to_excel(.  writer, sheet_name='download', index=False )
writer.save()

b64= base64.b64encode( output.getValue() ).decode()

fileName = "aaa.xlsx"

href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filenName}>{linkName}</a>"'