To read an Excel file in Databricks, upload the .xlsx file to a location Spark can reach (a Unity Catalog volume or DBFS), install the openpyxl and pandas libraries, then read it with pandas in a notebook and convert the result to a Spark or pandas DataFrame. Spark has no native Excel reader because Excel is not a splittable, schema-stable format, so the standard pattern is pandas (or a similar library) inside the cluster. Once the sheet is in a DataFrame you can query it with SQL, join it to other tables, or write it out as Parquet or a Delta table for faster reuse later.
What You'll Need
- An active Databricks workspace and a cluster you can attach a notebook to (a single-node cluster or a small cluster is enough for typical spreadsheets).
- Your Excel file saved locally as
.xlsx. Legacy.xlsfiles behave differently and are worth converting first. - A place to store the file: a Unity Catalog volume (
/Volumes/catalog/schema/volume/file.xlsx) if your workspace uses Unity Catalog, or the DBFS Filestore (/FileStore/) otherwise. - The
pandasandopenpyxlPython libraries, installed on the cluster or in the notebook. - Knowledge of which sheet you want and roughly where the header row sits, because business spreadsheets often have title rows above the real header.
Step-by-Step
Upload the file to a location Spark can read. In the workspace sidebar, open Catalog, browse to a volume you have write access to, and use the upload option; or use Data Ingestion / Add data and choose the upload path. Note the full path. If you use DBFS, the workspace file browser writes to
/FileStore/. Avoid storing the file in the notebook's working directory, which is not shared with the cluster in the way you might expect.Install the libraries. On the cluster page, open the Libraries tab and install
openpyxlandpandasfrom PyPI. Alternatively, run%pip install openpyxl pandasas the first cell of your notebook, then restart the Python process when Databricks prompts you to. Installing on the cluster is more reliable for scheduled jobs;%pipis quicker for exploration. Library and menu labels can differ slightly between workspace versions, so look for the equivalent wording if yours differs.Read the file with pandas. In a new cell, load the file and inspect the result before converting anything:
import pandas as pd path = "/Volumes/main/default/my_files/sales.xlsx" pdf = pd.read_excel(path, sheet_name="Sheet1", engine="openpyxl") print(pdf.shape) pdf.head()For DBFS paths use
/dbfs/FileStore/sales.xlsxwhen reading with pandas, since pandas talks to the local filesystem rather than through the Spark DFS layer. On Unity Catalog volumes, the/Volumes/...path works directly.List the sheets if you do not know them. Read the workbook's structure first rather than guessing names:
xl = pd.ExcelFile(path, engine="openpyxl") print(xl.sheet_names)Then pass the exact sheet name, or an index such as
sheet_name=0for the first tab.Fix the header and skipped rows. Real spreadsheets often start data below a title block. Use
header=to say which row holds the column names (zero-based) andskiprows=to discard preamble rows:pdf = pd.read_excel(path, sheet_name="Sheet1", header=2, skiprows=0, engine="openpyxl")Always re-print
pdf.columnsafter changing these, because off-by-one mistakes here are the most common cause of columns namedUnnamed: 0.Convert to a Spark DataFrame. For small to medium files, use
spark.createDataFrame(pdf). Two details matter: pandas may infer a column of mixed types asobject, and Spark cannot handle all dtypes directly. Convert explicitly, for examplepdf["amount"] = pd.to_numeric(pdf["amount"], errors="coerce"), then create the Spark frame:sdf = spark.createDataFrame(pdf) display(sdf)If you only need pandas operations, you can skip this and keep working in pandas — but you lose Spark's distributed processing, which is usually fine for Excel-sized data.
Validate before you trust it. Check row counts, column dtypes, and a few sample values. Look for nulls in key columns, numeric columns stored as text, and dates imported as strings. Use
sdf.printSchema()andsdf.count(). A quick sanity check now saves a painful debugging session later.Persist the result. Write the cleaned table so you never re-parse the workbook:
sdf.write.mode("overwrite").saveAsTable("catalog.schema.sales_from_excel")gives you a Delta table you can query with SQL and share with others. Excel files make poor long-term storage; a table is queryable, versioned, and fast.
Common Mistakes
The biggest one is trying to read Excel with spark.read.format("excel") without a third-party connector. Spark's built-in readers handle CSV, JSON, Parquet, ORC, Avro and text — not spreadsheets. You either use pandas plus openpyxl, or you install and configure a community Spark Excel connector. If you see UnsupportedOperationException or "Data source excel not found", this is why.
Second is the path mismatch. Pandas needs the local filesystem mount (/dbfs/...) on DBFS, while Spark SQL paths use dbfs:/.... Mixing the two produces FileNotFoundError or an empty read. On Unity Catalog volumes, use the /Volumes/ path with both.
Third is ignoring multi-sheet workbooks and merged cells. Merged cells return NaN in every row except the first, and a workbook with several tabs only returns the first unless you specify names. Fourth is assuming column types: Excel stores everything as typed cells but frequently produces text where you expect numbers, especially columns with currency symbols or thousands separators. Fifth is loading very large sheets into pandas — pandas holds everything in memory on the driver, so a workbook with hundreds of thousands of rows can exhaust driver memory. Split such files or convert to CSV first.
Tips
Read only what you need. Use usecols and nrows to sample a workbook during exploration: pd.read_excel(path, usecols="A:D", nrows=100, engine="openpyxl"). Use dtype={"id": str} to keep identifiers such as ZIP codes from losing leading zeros.
Wrap the reader in a small reusable function so every notebook handles paths and headers the same way. Store incoming spreadsheets in a dedicated volume with a clear folder per source, and convert on arrival to a Delta table — that turns an ad hoc workbook workflow into a repeatable pipeline. If the same file arrives on a schedule, use a Databricks job or Auto Loader on CSV exports instead of a notebook someone runs by hand. Finally, keep the original file untouched after upload; you may need to re-read it when requirements change.
If That Did Not Work
If openpyxl is missing, you will see ModuleNotFoundError. Reinstall it on the cluster, and remember that adding a library requires the cluster to restart before it is available. If the file opens but all data appears as NaN, the header row is probably wrong — re-check with pd.read_excel(..., header=None, nrows=10) to see the raw grid. If you get a permission error, confirm the volume path and your grants; on DBFS Filestore, the file must live under the mount path you are reading. If the read is extremely slow, the file is likely large or full of formulas — openpyxl evaluates stored values, not formulas, so recalc and save as values if results look stale.
Troubleshooting
FileNotFoundError despite a correct-looking path: print dbutils.fs.ls("dbfs:/FileStore/") to see what the cluster actually sees, then match the exact filename, including spaces and capitalisation.
Empty DataFrame with the expected columns: the header row is being read from a row that is blank or a merged title. Set header explicitly.
Wrong column names like Unnamed: 0: that pattern usually means a blank header cell or an index column. Use index_col=False to prevent pandas from stealing the first column as an index.
Spark fails on createDataFrame with a type error: mixed-type object columns. Cast them to a single type with astype(str) or pd.to_numeric(..., errors="coerce") before conversion, and check dates with pd.to_datetime.
Dates off by a day or appear as numbers: Excel stores dates as serial numbers. Pass parse_dates=["order_date"] or convert afterwards, and confirm the timezone expectation for your downstream tables.
Out of memory on the driver: reduce the sheet size, read in chunks with skiprows and nrows, or convert the file to CSV and let Spark read it natively in parallel.
Library install succeeds but import still fails: your notebook may be attached to a different cluster than the one you installed on. Check the cluster name in the notebook header and restart the cluster after installing.
Frequently Asked Questions
Can Spark read Excel files natively?
No. Spark's built-in formats are CSV, JSON, Parquet, ORC, Avro and text. Excel needs pandas with openpyxl, or a separate third-party Spark Excel connector installed on the cluster.
Should I use pandas or a Spark Excel connector?
Use pandas for typical business spreadsheets — it is simple and reliable. Reach for a connector only when you must read many large workbooks in parallel, and be prepared to vet and maintain that dependency.
How do I read a specific sheet by name?
Pass sheet_name="MyTab" to pd.read_excel. To read every sheet at once, use sheet_name=None, which returns a dictionary keyed by sheet name.
Why are my numbers imported as text?
Cells with currency symbols, percentages or thousands separators are often stored as text. Clean them with pd.to_numeric(pdf["col"].astype(str).str.replace(",", ""), errors="coerce") and inspect the nulls afterwards.
Where should I store the Excel file in Databricks?
A Unity Catalog volume is the recommended location in modern workspaces. DBFS Filestore still works for smaller files. Either way, read it there and convert to a managed table promptly.
Can I read an .xls file the same way?
Not with openpyxl, which only handles .xlsx and .xlsm. Convert the old file to .xlsx first, or use a library that supports the legacy binary format.