Browse Source

导出文件响应头类型

peng 2 years ago
parent
commit
115aba7604
1 changed files with 3 additions and 6 deletions
  1. 3 6
      AdminController/ServeManagementController.py

+ 3 - 6
AdminController/ServeManagementController.py

@@ -674,7 +674,7 @@ class serveManagement(View):
             rd_sheet = rd_book.sheet_by_index(0)
             rd_sheet = rd_book.sheet_by_index(0)
             # wt_book = copy(rd_book)
             # wt_book = copy(rd_book)
             # wt_sheet = wt_book.get_sheet(0)
             # wt_sheet = wt_book.get_sheet(0)
-            wt_book = xlwt.Workbook(encoding='utf8')
+            wt_book = xlwt.Workbook()
             wt_sheet = wt_book.add_sheet('对账结果', cell_overwrite_ok=True)
             wt_sheet = wt_book.add_sheet('对账结果', cell_overwrite_ok=True)
             row_start = 7
             row_start = 7
             for row in range(rd_sheet.nrows):
             for row in range(rd_sheet.nrows):
@@ -694,12 +694,9 @@ class serveManagement(View):
                     for index, value in enumerate(col_value_list):
                     for index, value in enumerate(col_value_list):
                         wt_sheet.write(row_start, index, value)
                         wt_sheet.write(row_start, index, value)
                     row_start += 1
                     row_start += 1
-            res = HttpResponse(content_type='application/vnd.ms-excel')
+            res = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
             res['Content-Disposition'] = 'attachment; filename={}'.format(escape_uri_path(file.name))
             res['Content-Disposition'] = 'attachment; filename={}'.format(escape_uri_path(file.name))
-            output = BytesIO()
-            wt_book.save(output)
-            output.seek(0)
-            res.write(output.getvalue())
+            wt_book.save(res)
             return res
             return res
         except Exception as e:
         except Exception as e:
             print(e)
             print(e)