Skip to content

Commit

Permalink
get sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Mar 28, 2024
1 parent aa1cdc4 commit 7b64d4b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/MadsIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ function checkhash(DATA::DATA)::Bool
end
end

function get_datasets(filename::AbstractString)
if !isfile(filename)
@error("File $(filename) does not exist!")
return []
end
datasets = [""]
e = lowercase(last(splitext(filename)))
if ((e == ".jld") || (e == ".jld2"))
if e == ".jld"
ds = JLD.load(filename)
else
ds = JLD2.load(filename)
end
datasets = collect(keys(ds))
println("Available datasets: $(datasets)")
elseif e == ".xlsx"
xb = XLSX.readxlsx(filename)
datasets = collect(XLSX.sheetnames(xb))
println("Available XLSX sheets: $(datasets)")
end
return datasets
end

function load_data(filename::AbstractString; dataset="", first_row::Union{Nothing,Int}=nothing)::DataFrames.DataFrame
if !isfile(filename)
@warn("File $(filename) does not exist!")
Expand All @@ -61,7 +84,7 @@ function load_data(filename::AbstractString; dataset="", first_row::Union{Nothin
elseif e == ".xlsx"
try
xb = XLSX.readxlsx(filename)
datasets = XLSX.sheetnames(xb)
datasets = collect(XLSX.sheetnames(xb))
println("Available XLSX sheets: $(datasets)")
if dataset in datasets
@info("Dataset $(dataset) loaded from $(filename) ...")
Expand All @@ -81,7 +104,7 @@ function load_data(filename::AbstractString; dataset="", first_row::Union{Nothin
else
ds = JLD2.load(filename)
end
datasets = keys(ds)
datasets = collect(keys(ds))
println("Available datasets: $(datasets)")
if dataset in datasets
@info("Dataset $(dataset) loaded from $(filename) ...")
Expand Down

0 comments on commit 7b64d4b

Please sign in to comment.