parameters: (request)
return_statement: return render(request,'asset_list.html')
docstring: 导出excel表格
docstring_summary: 导出excel表格
docstring_tokens: 导出excel表格
function: def excel_export(request):
      """
      导出excel表格
      """
      import os
      list_obj = domain_ip.objects.all()
      if list_obj:
          # 创建工作薄
          ws = Workbook(encoding='utf-8')
          w = ws.add_sheet(u"数据报表")
          w.write(0, 0, "id")
          w.write(0, 1, u"域名")
          # 写入数据
          excel_row = 1
          for obj in list_obj:
              data_id = obj.id
              data_domain = obj.subdomain
              w.write(excel_row, 0, data_id)
              w.write(excel_row, 1, data_domain)
              excel_row += 1
          # 检测文件是够存在
          # 方框中代码是保存本地文件使用，如不需要请删除该代码
          ###########################
          exist_file = os.path.exists("static/upload/test.xls")
          if exist_file:
              os.remove(r"static/upload/test.xls")
          ws.save("static/upload/test.xls")
          the_file_name = 'static/upload/test.xls'  # 显示在弹出对话框中的默认的下载文件名
          filename = 'static/upload/test.xls'  # 要下载的文件路径
          response = StreamingHttpResponse(readFile(filename))
          response['Content-Type'] = 'application/octet-stream'
          response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name)
          return response
  
      return render(request,'asset_list.html')
function_tokens: def excel_export ( request ) : import os list_obj = domain_ip . objects . all ( ) if list_obj : # 创建工作薄 ws = Workbook ( encoding = 'utf-8' ) w = ws . add_sheet ( u"数据报表") w . write ( 0 , 0 , "id" ) w . write ( 0 , 1 , u"域名") # 写入数据 excel_row = 1 for obj in list_obj : data_id = obj . id data_domain = obj . subdomain w . write ( excel_row , 0 , data_id ) w . write ( excel_row , 1 , data_domain ) excel_row += 1 # 检测文件是够存在 # 方框中代码是保存本地文件使用，如不需要请删除该代码 ########################### exist_file = os . path . exists ( "static/upload/test.xls" ) if exist_file : os . remove ( r"static/upload/test.xls" ) ws . save ( "static/upload/test.xls" ) the_file_name = 'static/upload/test.xls' # 显示在弹出对话框中的默认的下载文件名 filename = 'static/upload/test.xls' # 要下载的文件路径 response = StreamingHttpResponse ( readFile ( filename ) ) response [ 'Content-Type' ] = 'application/octet-stream' response [ 'Content-Disposition' ] = 'attachment;filename="{0}"' . format ( the_file_name ) return response return render ( request , 'asset_list.html' )