Skip to content

Files

61 lines (40 loc) · 2.07 KB

GitHub_Download_Excel_file_from_URL.md

File metadata and controls

61 lines (40 loc) · 2.07 KB



Template request | Bug report | Generate Data Product

Tags: #github #excel #download #url #file #python

Author: Florent Ravenel

Description: This notebook explains how to download an Excel file stored on a GitHub repository.

References:

Input

Import libraries

import requests
import pandas as pd

Setup Variables

  • url: URL of the Excel file stored on GitHub
  • output_path: Name of the output to be saved on your local
# Inputs
url = "https://github.com/jupyter-naas/awesome-notebooks/blob/master/Excel/Conso.xlsx"

# Outputs
output_path = "Excel.xlsx"

Model

Download Excel file

def download_excel_file(url, output_path):
    # Check URL
    if not url.endswith("?raw=true") and url.endswith(".xlsx"):
        url = f'{url}?raw=true'
        
    # Get file
    response = requests.get(url)
    with open(output_path, "wb") as f:
        f.write(response.content)
    print("✅ Excel file successfully saved:", output_path)

Output

Display result

download_excel_file(url, output_path)