def test_file_download(request):
wb = export_to_xls()
response = HttpResponse()
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="test.xls"'
wb.save(response)
return response

def export_to_xls():
style0 = xlwt.easyxf('font: name Times New Roman, color-index black, bold on',num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
ws.write(0, 0, 1234.56, style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
return wb

相关文章:

  • 2021-05-17
  • 2021-12-10
  • 2022-12-23
  • 2021-11-13
  • 2021-11-17
  • 2021-05-28
  • 2022-01-07
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2021-06-25
  • 2021-06-30
  • 2022-12-23
  • 2021-08-14
相关资源
相似解决方案