Excel Files
Reading and writing XLSX files are made possible by XLSX.jl
read_xlsx
¤
readxlsx(path; sheet=nothing, range=nothing, colnames=true, coltypes=nothing, missingstring="", trimws=true, skip=0, nmax=Inf, guessmax=nothing)
This function reads data from an Excel file into a DataFrame. The arguments are:
path
: The path or URL to the Excel file to be read.sheet
: The sheet to be read. Can be a sheet name (string) or index (integer). Default is the first sheet.range
: A specific range of cells to be read from the sheet. Default is the entire sheet.col_names
: Whether the first row of the range contains column names. Default istrue
.col_types
: Explicit specification of column types. Can be a single type, a list, or a dictionary mapping column names or indices to types. Default isnothing
(types are inferred).missingstring
: The string representing missing values. Default is""
.trim_ws
: Whether to trim leading and trailing whitespace from cells. Default istrue
.skip
: Number of rows to skip before reading data. Default is 0.n_max
: Maximum number of rows to read. Default isInf
(read all rows).guess_max
: Maximum number of rows to scan for type guessing and column names detection. Default isnothing
(a default heuristic is used).
write_xlsx
¤
write_xlsx(x; path, overwrite=false)
This function writes a DataFrame, or multiple DataFrames, to an Excel file. The arguments are:
x
: The data to write. Can be a singlePair{String, DataFrame}
for writing one sheet, or aTuple
of such pairs for writing multiple sheets. TheString
in each pair specifies the sheet name, and theDataFrame
is the data to write to that sheet.path
: The path to the output Excel file.overwrite
: Whether to overwrite an existing file. Default isfalse
.
Writing to a specific sheet¤
The example below demonstrates how to write to specific sheets in a file. The string in the Dict
is the sheet name, it can be new or preexisting. The second component is the dataframe to be written to that sheet. In this example, two sheets, "REPORTA" and "REPORTC" are being written to with df
and df2
respectively.
write_xlsx(("REPORT_A" => df, "REPORT_C" => df2); path = "/Users/danielrizk/Downloads/xlsxtest2.xlsx", overwrite = true)
This page was generated using Literate.jl.