excel (DataFrameReader)
Loads Excel files and returns the result as a DataFrame.
Syntax
excel(path, dataAddress=None, headerRows=None, listSheets=None,
dateFormat=None, timestampFormat=None)
Parameters
Parameter | Type | Description |
|---|---|---|
| str or list | One or more input paths. |
| str, optional | The address of the data within the Excel file. |
| int or str, optional | The number of header rows. |
| bool or str, optional | If |
| str, optional | The date format string. |
| str, optional | The timestamp format string. |
Returns
DataFrame
Examples
Write a DataFrame into an Excel file and read it back.
Python
import tempfile
with tempfile.TemporaryDirectory(prefix="excel") as d:
spark.createDataFrame(
[{"age": 100.1, "name": "Alice"}]
).write.mode("overwrite").option("headerRows", 1).excel(d)
spark.read.excel(d, headerRows=1).show()
# +-----+------------+
# | age| name|
# +-----+------------+
# |100.1|Alice|
# +-----+------------+