Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support IO for writetable #245

Merged
merged 3 commits into from
Dec 7, 2023
Merged

Conversation

hhaensel
Copy link
Contributor

This PR should fix #78

@hhaensel
Copy link
Contributor Author

hhaensel commented Nov 24, 2023

I tried reading directly from io for the runtests.jl, but that failed. Maybe that's for another issue ...?

EDIT: I was stupid. I forgot to reset the io buffer before testing. So no new issue...
... and a nicer test routine

@hhaensel
Copy link
Contributor Author

hhaensel commented Nov 28, 2023

While this is not in place, I helped myself with the following workaround

function XLSX.writetable(io::IO, tables::Union{Vector, Tuple}; kwargs...)
    XLSX.openxlsx(io, mode="w") do xf
        for (i, table) in enumerate(tables)
            table isa Pair || (table = nothing => table)
            if i == 1
                table[1] !== nothing && XLSX.rename!(xf[1], table[1])
            else
                table[1] === nothing ? XLSX.addsheet!(xf) : XLSX.addsheet!(xf, table[1])
            end
            XLSX.writetable!(xf[i], table[2]; kwargs...)
        end
    end
end

XLSX.writetable(io, tables; kwargs...) = XLSX.writetable(io, [tables]; kwargs...)
XLSX.writetable(io, tables...; kwargs...) = XLSX.writetable(io, tables; kwargs...)

@felipenoris
Copy link
Owner

Looks good. Thanks!

@felipenoris felipenoris merged commit edba58c into felipenoris:master Dec 7, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write to IO
2 participants