通过url获取Excel,用pandas读取

obj = ObjDnCarBookingPlan.query.filter().first()
            file_path = obj.car_booking_plan
            logging.info(f"file_path查询结果为:{file_path}")
            url = file_path
            # 获取Excel文件
            r = requests.get(url)
            # 解析文件
            res = r.content
            now_time = datetime.datetime.now()
            file_time = now_time.strftime(r'%Y%m%d%H%M%S')
            file_path = '../static/upload'
            logging.warning('文件保存路径file_path' + file_path)
            if not os.path.exists(file_path):
                os.makedirs(file_path)
            else:
                pass
            file_name = file_path + '/' + file_time + 'SC走货信息.xlsx'
            with open(file_name,'wb') as f:
                f.write(res)
            df = pd.read_excel(file_name, header=5)

 

posted @ 2021-10-29 11:04  这世界我来过  阅读(450)  评论(0)    收藏  举报