Django包,可轻松呈现Excel电子表格
django-excel-response的Python项目详细描述
将转换QuerySet的HttpResponse的子类, 或序列,输入Excel电子表格或 为Excel格式化的CSV文件,具体取决于数据量
安装
pip install django-excel-response
提供的类
excel_response.response.ExcelResponse
Accepted arguments:
- ^{tt2}$ - A queryset or list of lists from which to construct the output
- ^{tt3}$ - The filename which should be suggested in the http response, minus the file extension (default: excel_data)
- ^{tt4}$ - The name of the worksheet inside the spreadsheet into which the data will be inserted (default: None)
- ^{tt5}$ - A boolean stating whether to force CSV output (default: False)
- ^{tt6}$ - The font to be applied to the header row of the spreadsheet; must be an instance of ^{tt7}$ (default: None)
- ^{tt8}$ - The font to be applied to all data cells in the spreadsheet; must be an instance of ^{tt7}$ (default: None)
excel_response.views.ExcelMixin
excel_response.views.ExcelView
示例
基于功能的视图
您可以从queryset构造数据
fromexcel_responseimportExcelResponsedefexcelview(request):objs=SomeModel.objects.all()returnExcelResponse(objs)
或者可以手动构造数据。
fromexcel_responseimportExcelResponsedefexcelview(request):data=[['Column 1','Column 2'],[1,2][23,67]]returnExcelResponse(data,'my_data')
基于类的视图
这些都是简单的进口和去
fromexcel_responseimportExcelViewclassModelExportView(ExcelView):model=SomeModel