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