Search code examples
exceldataframejuliaxlsx

Error when going from dataframe to excel file in Julia


I am trying to export a dataframe to xlsx

df |> XLSX.writexlsx("df.xlsx")

and am getting this error:

ERROR: Unsupported datatype String31 for writing data to Excel file. Supported data types are Union{Missing, Bool, Float64, Int64, Dates.Date, Dates.DateTime, Dates.Time, String} or XLSX.CellValue.

I cannot find anyting about String31 utilizing Google. Is there a "transform" that I need to perform on the df beforehand?


Solution

  • It seems that currently this is a limitation of XSLX.jl. I have opened an issue proposing to fix it.

    I assume your df is not huge, in which case the following solution should work for you:

    to_string(x::AbstractString) = String(x)
    to_string(x::Any) = x
    XLSX.writetable("df.xlsx", to_string.(df))