我在 python Django 中创建下载的动态 Excel 文件(未存储在本地),我需要使工作表从右到左而不是从左到右显示。
这是我使用的代码:
import pandas
from io import BytesIO, StringIO
sio = BytesIO()
PandasDataFrame = pandas.DataFrame([['t1', 't2'], ['t3', 't4']], index = ['t1', 't2'], columns = ['t11', 't1'] )
PandasWriter = pandas.ExcelWriter(sio, engine='xlsxwriter')
PandasDataFrame.to_excel(PandasWriter, sheet_name='Sheet1')
PandasWriter.book.add_format({'reading_order': 2})
PandasWriter.save()
PandasWriter.close()
sio.seek(0)
workbook = sio.read()
response = HttpResponse(workbook,content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = 'attachment; filename=wrong_data.xlsx'
return (response)
Run Code Online (Sandbox Code Playgroud)