November 3rd, 2021 12:00 PM EDT
Automation for Field Services & DistributionNovember 3rd, 2021 12:00 PM EDT
Learn how creating a digital workforce can improve your supply chain processes!

Downloading and reading an Excel file

This example demonstrates how to download and how to read data from an Excel file. We will use RPA.Excel.Files and RPA.HTTP libraries from the RPA Framework.

Robot Framework example

*** Settings ***
Documentation   Download an Excel file and read the rows.
Library         RPA.Excel.Files
Library         RPA.HTTP

*** Variables ***
${EXCEL_FILE_URL}=  https://github.com/robocorp/example-web-store-order-processor/raw/main/devdata/Data.xlsx

*** Tasks ***
Download an Excel file and read the rows
    Download        ${EXCEL_FILE_URL}           overwrite=True
    Open Workbook   Data.xlsx
    ${table}=       Read Worksheet As Table     header=True
    Close Workbook

    FOR     ${row}  IN  @{table}
        Log     ${row}

Python example

from RPA.Excel.Files import Files
from RPA.HTTP import HTTP

excel_lib = Files()
http_lib = HTTP()

excel_file_url= "https://github.com/robocorp/example-web-store-order-processor/raw/main/devdata/Data.xlsx"

def download_the_excel_file(url):
    http_lib.download(url, overwrite=True)

def open_the_file_as_table():
    table = excel_lib.read_worksheet_as_table(header=True)
    return table

def loop_over_table(table):
    for row in table:

# Define a main() function that calls the other functions in order:
def main():
    table = open_the_file_as_table()

# Call the main() function, checking that we are running as a stand-alone script:
if __name__ == "__main__":

See RPA.Excel.Files keyword documentation to learn more about working with Excel files.

Learn more about the libraries mentioned on this page:

May 19, 2021