xlsx.read
result = xlsx.read(path, [sheet], [headers=true])
Input: path, sheet, headers · Output: result
What it is
Reads one worksheet of a workbook into a Table, the same type read_csv produces, so everything that consumes a CSV consumes a spreadsheet unchanged. path (string) is the .xlsx file. sheet (string, optional, positional or sheet=) picks it by name; omitting it takes the first. headers (boolean, optional, default true) — false treats the first row as data and names the columns by position (A, B, C) instead.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = xlsx.read(path, [sheet], [headers=true]) | path stringpath (string) is the .xlsx file.sheet string, optionalsheet (string, optional, positional or sheet=) picks it by name.headers boolean, optional (default true)headers (boolean, optional, default true) — false treats the first row as data and names the columns by position (A, B, C) instead. | result Table | Returns a Table, one column per spreadsheet column, each column numeric or text according to what the cells hold. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
import xlsx
t = table(city = ("Aachen", "Bonn", "Cologne"), pop = (249, 331, 1087))
xlsx.write("cities.xlsx", t, sheet = "Cities")
print(xlsx.sheets("cities.xlsx")) # ("Cities")
print(xlsx.read("cities.xlsx")) # a Table, city/pop
print(xlsx.read("cities.xlsx", headers = false))
output
("Cities")
city pop
------- ----
Aachen 249
Bonn 331
Cologne 1087
A B
------- ----
city pop
Aachen 249
Bonn 331
Cologne 1087from file-io