< Summary

Class:src/writer.jl
Assembly:Default
File(s):src/writer.jl
Covered lines:21
Uncovered lines:0
Coverable lines:21
Total lines:47
Line coverage:100% (21 of 21)
Covered branches:0
Total branches:0
Tag:43_456648716

File(s)

src/writer.jl

#LineLine coverage
 31JSON.json(jws::JSONWorksheet) = JSON.json(data(jws))
 52JSON.json(jws::JSONWorksheet, indent) = JSON.json(data(jws), indent)
 3
 4function write(file::Union{String, IO}, jws::JSONWorksheet; indent = 2, drop_null = false)
 65    open(file, "w") do io
 6        data = JSON.json(jws, indent)
 7        # drop null array such as [null, null, ....]
 8        if drop_null
 9            data = replace(data, r"(\"[\w]*\":null,)|(,?\"[\w]*\":null)" => "")
 10        end
 11        Base.write(io, data)
 12    end
 13end
 14
 15function write(path::String, jwb::JSONWorkbook; kwargs...)
 216    f = splitext(basename(xlsxpath(jwb)))[1]
 117    for s in sheetnames(jwb)
 318        write(joinpath(path, "$(f)_$(s).json"), jwb[s]; kwargs...)
 19    end
 20end
 21
 22function write_xlsx(file::String, jwb::JSONWorkbook; delim = ";", anchor_cell = "A1")
 223    XLSX.openxlsx(file, mode="w") do xf
 24
 225        for (i, s) in enumerate(sheetnames(jwb))
 326            jws = jwb[s]
 327            if i == 1
 128                sheet = xf[1]
 129                XLSX.rename!(sheet, s)
 30            else
 231                sheet = XLSX.addsheet!(xf, s)
 32            end
 33
 334            labels = map(el -> "/" * join(el.tokens, "/"), jws.pointer)
 335            columns = []
 336            for p in jws.pointer
 3237                data = get.(jws.data, Ref(p), missing)
 3238                if eltype(data) <: Array
 439                    data = join.(data, delim)
 40                end
 3541                push!(columns, data)
 42            end
 43
 344            XLSX.writetable!(sheet, columns, labels, anchor_cell=XLSX.CellRef(anchor_cell))
 45        end
 46    end
 47end

Methods/Properties