< Summary

Information
Class: src/writer.jl
Assembly: Default
File(s): src/writer.jl
Tag: 40_3060321334
Line coverage
96%
Covered lines: 29
Uncovered lines: 1
Coverable lines: 30
Total lines: 51
Line coverage: 96.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

File(s)

src/writer.jl

#LineLine coverage
 61function write(file::AbstractString, jws::JSONWorksheet; kwargs...)
 62    open(file, "w") do io
 33        write(io, jws; kwargs...)
 4    end
 5end
 106function write(io::IO, jws::JSONWorksheet; indent = 2, drop_null = false)
 107    if indent > 0
 48        JSON.print(io, Tables.rows(jws), indent)
 9    else
 110        JSON.print(io, Tables.rows(jws))
 11    end
 12    # drop null array such as [null, null, ....]
 513    if drop_null
 014        replace!(io, r"(\"[\w]*\":null,)|(,?\"[\w]*\":null)" => "")
 15    end
 516    return io
 17end
 18
 219function write(path::String, jwb::JSONWorkbook; kwargs...)
 220    f = splitext(basename(xlsxpath(jwb)))[1]
 121    for s in sheetnames(jwb)
 322        write(joinpath(path, "$(f)_$(s).json"), jwb[s]; kwargs...)
 23    end
 24end
 25
 226function write_xlsx(file::String, jwb::JSONWorkbook; delim = ";", anchor_cell = "A1")
 227    XLSX.openxlsx(file, mode="w") do xf
 28
 229        for (i, s) in enumerate(sheetnames(jwb))
 330            jws = jwb[i]
 331            if i == 1
 132                sheet = xf[1]
 133                XLSX.rename!(sheet, s)
 34            else
 235                sheet = XLSX.addsheet!(xf, s)
 36            end
 37
 638            colnames = pointer_to_colname.(jws.pointer)
 339            columns = []
 340            for p in jws.pointer
 3241                data = get.(jws.data, Ref(p), missing)
 3242                if eltype(data) <: Array
 443                    data = join.(data, delim)
 44                end
 3545                push!(columns, data)
 46            end
 47
 348            XLSX.writetable!(sheet, columns, colnames, anchor_cell=XLSX.CellRef(anchor_cell))
 49        end
 50    end
 51end

Methods/Properties