felipenoris / XLSX.jl

Excel file reader and writer for the Julia language.
https://felipenoris.github.io/XLSX.jl/stable
Other
265 stars 54 forks source link

DataFrames #240

Open ymer opened 9 months ago

ymer commented 9 months ago

The tutorial says I should read to a DataFrame like this: DataFrame(XLSX.readtable("myfile.xlsx", "mysheet"))

However, this gives an error:

using DataFrames, XLSX
df = DataFrames.DataFrame(integers=[1, 2, 3, 4], strings=["Hey", "You", "Out", "There"])
XLSX.writetable("df.xlsx", df)

DataFrame(XLSX.readtable("df.xlsx", "Sheet1"))

While this works:

(cols, colnames) = XLSX.readtable("df.xlsx", "Sheet1")
df = DataFrame(cols, Symbol.(colnames))
jvigneron commented 9 months ago

With the latest versions (DataFrames v1.6.1 & XLSX v0.10.0) , your first example works as expected but the second one thows an error :

  (cols, colnames) = XLSX.readtable("df.xlsx", "Sheet1") # ERROR: MethodError: no method matching iterate(::XLSX.DataTable)
nilshg commented 6 months ago

This sounds like you're just on an old version of XLSX.jl - it used to return a data/column names tuple (so you had to do DataFrame(XLSX.readtable("myfile.xlsx", 1)...)) but since version 0.8 it returns a Tables.jl compatible object so you can construct the DataFrame directly, see:

https://felipenoris.github.io/XLSX.jl/dev/migration/#Migrating-Legacy-Code-to-v0.8

Please check ] st in the environment in which you are running your code. If you can reproduce your issue on the latest XLSX version (0.10) please report back here, otherwise the issue can be closed.

nilshg commented 1 month ago

This is probably good to close?