Import excel spreadsheet to a database table

MGraham
New Contributor

How to Import excel spreadsheet to a database table.

jerrygen78
New Contributor III

Hi MGraham,

To import an Excel spreadsheet into a database table in Databricks, you can first upload the Excel file to DBFS (Databricks File System), then use libraries like pandas to read the Excel file (e.g., pd.read_excel("/dbfs/path/to/file.xlsx")) and convert it to a Spark DataFrame. Once in a DataFrame, you can write it to a database table using .write.format("jdbc") for external databases or .write.saveAsTable("table_name") for internal Databricks tables. Let me know if you'd like a quick code example!

Regards

FedeRaimondi
Contributor II

An alternative is also to store the flat file into a Volume in Unity Catalog. You can then access it in a similar way:

 

import pandas as pd

volume_path= "/Volumes/<catalog>/<schema>/<volume_folder>/your_file.xlsx"
pd.read_excel(volume_path, sheet_name="your_sheet")