| | 6 | 1 | | function write(file::AbstractString, jws::JSONWorksheet; kwargs...) |
| | 3 | 2 | | open(file, "w") do io |
| | 3 | 3 | | write(io, jws; kwargs...) |
| | | 4 | | end |
| | | 5 | | end |
| | 18 | 6 | | function write(io::IO, jws::JSONWorksheet; |
| | | 7 | | indent = 2, |
| | | 8 | | omit_null::Bool = false, |
| | | 9 | | omit_empty::Bool = false) |
| | 9 | 10 | | JSON.json(io, jws.data; |
| | | 11 | | pretty = indent, |
| | | 12 | | omit_null = omit_null, |
| | | 13 | | omit_empty = omit_empty) |
| | 9 | 14 | | return io |
| | | 15 | | end |
| | | 16 | | |
| | 2 | 17 | | function write(path::String, jwb::JSONWorkbook; kwargs...) |
| | 1 | 18 | | f = splitext(basename(xlsxpath(jwb)))[1] |
| | 1 | 19 | | for s in sheetnames(jwb) |
| | 3 | 20 | | write(joinpath(path, "$(f)_$(s).json"), jwb[s]; kwargs...) |
| | 3 | 21 | | end |
| | | 22 | | end |
| | | 23 | | |
| | 2 | 24 | | function write_xlsx(file::String, jwb::JSONWorkbook; delim = ";", anchor_cell = "A1") |
| | 1 | 25 | | XLSX.openxlsx(file, mode="w") do xf |
| | | 26 | | |
| | 1 | 27 | | for (i, s) in enumerate(sheetnames(jwb)) |
| | 3 | 28 | | jws = jwb[i] |
| | 3 | 29 | | if i == 1 |
| | 1 | 30 | | sheet = xf[1] |
| | 1 | 31 | | XLSX.rename!(sheet, s) |
| | | 32 | | else |
| | 2 | 33 | | sheet = XLSX.addsheet!(xf, s) |
| | | 34 | | end |
| | | 35 | | |
| | 3 | 36 | | colnames = pointer_to_colname.(jws.pointer) |
| | 3 | 37 | | columns = [] |
| | 3 | 38 | | for p in jws.pointer |
| | 32 | 39 | | data = get.(jws.data, Ref(p), missing) |
| | 32 | 40 | | if eltype(data) <: Array |
| | 4 | 41 | | data = join.(data, delim) |
| | | 42 | | end |
| | 32 | 43 | | push!(columns, data) |
| | 32 | 44 | | end |
| | | 45 | | |
| | 3 | 46 | | XLSX.writetable!(sheet, columns, colnames, anchor_cell=XLSX.CellRef(anchor_cell)) |
| | 3 | 47 | | end |
| | | 48 | | end |
| | | 49 | | end |