Django框架---上传Excel文件并读取

def upload_file(request):
    if request.method == "POST":
        File = request.FILES.get("files", None)
        if File is None:
            return HttpResponse("请选择需要上传的文件")
        else:
            # with open("./%s" % File.name, 'wb+') as  f:
            #     for chunk in File.chunks():
            #         f.write(chunk)
            f = open(os.path.join(BASE_DIR, File.name), 'wb')
            for chunk in File.chunks():
                f.write(chunk)
            f.close()
            excel_type = f.name.split('.')[-1]
            # if excel_type in ['xlsx', 'xls','csv']:
            #     # 开始解析上传的excel表格
            #     # file_contents = f.open(os.path.join(BASE_DIR, File.name), 'r')
            #     wb = xlrd.open_workbook(filename=File, file_contents=f.read())
            #     table = wb.sheets()[0]
            #     rows = table.nrows  # 总行数
            # f.close()
            return render(request, "index.html")
    else:
        return render(request, "index.html")



    
    MonkeyTest


    
{% csrf_token %}

请上传文件

请输入执行人: 请输入部门:
请上传文件

文件上传执行结果:
ID 执行人 部门 xxx 是否执行完 备注



    
    
    
    
    Document
    
	
        


    

    

系统提示

×

亲!请关注近期的优惠活动!

 

你可能感兴趣的:(前端)