-
Notifications
You must be signed in to change notification settings - Fork 63
WIP: Supporting XML v0.4 #361
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
Draft
joshday
wants to merge
6
commits into
JuliaData:master
Choose a base branch
from
joshday:xml-v0.4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
79be5f6
first pass
joshday 4c52dd7
ci
joshday 0412e1f
Optimize SST loading and cell read perf
joshday 0f274d3
Adapt cell and SST reading for XML v0.4 APIs
joshday 68e524c
Merge origin/master into xml-v0.4
joshday ad3bd54
Fix no-default-namespace read path (XML v0.4)
joshday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ Manifest.toml | |
| docs/Manifest.toml | ||
| .vscode | ||
| *.gz | ||
| .claude | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,8 +113,9 @@ const EXCEL_COLUMN_WIDTH_PADDING = 0.7109375 | |
| # | ||
|
|
||
| function copynode(o::XML.Node) | ||
| n = XML.Node(o.nodetype, o.tag, o.attributes, o.value, isnothing(o.children) ? nothing : [copynode(x) for x in o.children]) | ||
| return n | ||
| attrs = isnothing(o.attributes) ? nothing : copy(o.attributes) | ||
| children = isnothing(o.children) ? nothing : XML.Node{String}[copynode(x) for x in o.children] | ||
| return XML.Node{String}(o.nodetype, o.tag, attrs, o.value, children) | ||
| end | ||
| function do_sheet_names_match(ws::Worksheet, rng::T) where {T<:Union{SheetCellRef,AbstractSheetCellRange}} | ||
| if ws.name == rng.sheet | ||
|
|
@@ -125,8 +126,8 @@ function do_sheet_names_match(ws::Worksheet, rng::T) where {T<:Union{SheetCellRe | |
| end | ||
|
|
||
| function make_child_node(tag::String, name::String, pfx::String)::XML.Node | ||
| children = tag ∈ ("border", "fill") ? Vector{XML.Node}() : nothing | ||
| return XML.Node(XML.Element, pfx*name, OrderedDict{String,String}(), nothing, children) | ||
| children = tag ∈ ("border", "fill") ? Vector{XML.Node{String}}() : nothing | ||
| return XML.Node{String}(XML.Element, pfx*name, Pair{String,String}[], nothing, children) | ||
| end | ||
|
|
||
| function build_font_child!(new_node::XML.Node, tag::String, name::String, attrs::Union{Nothing,Dict{String,String}}, pfx::String) | ||
|
|
@@ -216,7 +217,7 @@ end | |
| if isnothing(attributes[a]) | ||
| cnode = XML.Element(a) | ||
| else | ||
| cnode = XML.Node(XML.Element, a, OrderedDict{String,String}(), nothing, tag ∈ ["border", "fill"] ? Vector{XML.Node}() : nothing) | ||
| cnode = XML.Node{String}(XML.Element, a, Pair{String,String}[], nothing, tag ∈ ["border", "fill"] ? Vector{XML.Node{String}}() : nothing) | ||
| for (k, v) in attributes[a] | ||
| cnode[k] = v | ||
| end | ||
|
|
@@ -228,7 +229,7 @@ end | |
| if isnothing(attributes[a]) | ||
| cnode = XML.Element(a) | ||
| else | ||
| cnode = XML.Node(XML.Element, a, OrderedDict{String,String}(), nothing, tag ∈ ["border", "fill"] ? Vector{XML.Node}() : nothing) | ||
| cnode = XML.Node{String}(XML.Element, a, Pair{String,String}[], nothing, tag ∈ ["border", "fill"] ? Vector{XML.Node{String}}() : nothing) | ||
| color = XML.Element("color") | ||
| for (k, v) in attributes[a] | ||
| if k == "style" && v != "none" | ||
|
|
@@ -255,7 +256,7 @@ end | |
| if isnothing(attributes[a]) | ||
| cnode = XML.Element(a) | ||
| else | ||
| cnode = XML.Node(XML.Element, a, OrderedDict{String,String}(), nothing, tag ∈ ["border", "fill"] ? Vector{XML.Node}() : nothing) | ||
| cnode = XML.Node{String}(XML.Element, a, Pair{String,String}[], nothing, tag ∈ ["border", "fill"] ? Vector{XML.Node{String}}() : nothing) | ||
| patternfill = XML.Element("patternFill") | ||
| fgcolor = XML.Element("fgColor") | ||
| bgcolor = XML.Element("bgColor") | ||
|
|
@@ -475,14 +476,14 @@ function get_new_formatId(wb::Workbook, format::String)::Int | |
| if isnothing(j) # There are no existing custom formats | ||
| return styles_add_numFmt(wb, format) | ||
| else | ||
| existing_elements_count = length(XML.children(xroot[i][j])) | ||
| existing_elements_count = length(xml_elements(xroot[i][j])) | ||
| if parse(Int, xroot[i][j]["count"]) != existing_elements_count | ||
| throw(XLSXError("Wrong number of font elements found: $existing_elements_count. Expected $(parse(Int, xroot[i][j]["count"])).")) | ||
| end | ||
|
|
||
| format_node = XML.Element("numFmt"; | ||
| numFmtId=string(existing_elements_count + PREDEFINED_NUMFMT_COUNT), | ||
| formatCode=XLSX.escape(format) | ||
| formatCode=format | ||
| ) | ||
|
|
||
| return styles_add_cell_attribute(wb, format_node, "numFmts") + PREDEFINED_NUMFMT_COUNT | ||
|
|
@@ -529,7 +530,7 @@ function update_template_xf(ws::Worksheet, allXfNodes::Vector{XML.Node}, existin | |
| old_cell_xf = styles_cell_xf(allXfNodes, Int(existing_style.id)) | ||
| new_cell_xf = copynode(old_cell_xf) | ||
| if isnothing(new_cell_xf.children) | ||
| new_cell_xf=XML.Node(new_cell_xf, alignment) | ||
| new_cell_xf = XML.Node{String}(XML.Element, XML.tag(new_cell_xf), new_cell_xf.attributes, nothing, XML.Node{String}[alignment]) | ||
| elseif length(XML.children(new_cell_xf)) == 0 | ||
| push!(new_cell_xf, alignment) | ||
| else | ||
|
|
@@ -550,14 +551,14 @@ end | |
| function styles_add_cell_attribute(wb::Workbook, new_att::XML.Node, att::String)::Int | ||
| xroot = styles_xmlroot(wb) | ||
| i, j = get_idces(xroot, "styleSheet", att) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| existing_elements_count = length(XML.children(xroot[i][j])) | ||
| existing_elements_count = length(xml_elements(xroot[i][j])) | ||
| if parse(Int, xroot[i][j]["count"]) != existing_elements_count | ||
| throw(XLSXError("Wrong number of elements elements found: $existing_elements_count. Expected $(parse(Int, xroot[i][j]["count"])).")) | ||
| end | ||
|
|
||
| # Check new_att doesn't duplicate any existing att. If yes, use that rather than create new. | ||
| for (k, node) in enumerate(XML.children(xroot[i][j])) | ||
| if localname(new_att) == "numFmt" # mustn't compare numFmtId attribute for formats | ||
| for (k, node) in enumerate(xml_elements(xroot[i][j])) | ||
| if XML.tag(new_att) == "numFmt" # mustn't compare numFmtId attribute for formats | ||
| if node["formatCode"] == new_att["formatCode"] | ||
| return k - 1 # CellDataFormat is zero-indexed | ||
| end | ||
|
|
@@ -1110,7 +1111,7 @@ function process_uniform_core(f::Function, ws::Worksheet, allXfNodes::Vector{XML | |
| if first # Get the attribute of the first cell in the range. | ||
| newid = f(ws, cellref; kw...) | ||
| new_alignment = getAlignment(ws, cellref).alignment["alignment"] | ||
| alignment_node = XML.Node(XML.Element, "alignment", new_alignment, nothing, nothing) | ||
| alignment_node = XML.Node{String}(XML.Element, "alignment", isnothing(new_alignment) ? Pair{String,String}[] : Pair{String,String}[k => v for (k,v) in new_alignment], nothing, nothing) | ||
| first = false | ||
| else # Apply the same attribute to the rest of the cells in the range. | ||
| if cell.style == UInt64(0) | ||
|
|
@@ -1320,12 +1321,12 @@ function update_sharedString_font(ws::Worksheet, cell::Cell; | |
|
|
||
| is = parse(str_formatted, XML.Node)[1] # Convert to XML.Node for ease of handling | ||
|
|
||
| all_r = filter(z -> z.tag == "r", XML.children(is)) | ||
| all_r = filter(z -> localname(z) == "r", XML.children(is)) | ||
| run_elements = reduce(vcat, [XML.children(z) for z in all_r]) | ||
| rPr_elements=filter(z -> z.tag == "rPr", run_elements) # rPr elements | ||
| rPr_elements = filter(z -> localname(z) == "rPr", run_elements) # rPr elements | ||
|
|
||
| t=String[] # text elements | ||
| for i in filter(z -> z.tag == "t", run_elements) | ||
| for i in filter(z -> localname(z) == "t", run_elements) | ||
| push!(t, XML.is_simple(i[1]) ? XML.simple_value(i[1]) : XML.value(i[1])) | ||
| end | ||
|
|
||
|
|
@@ -1337,7 +1338,7 @@ function update_sharedString_font(ws::Worksheet, cell::Cell; | |
|
|
||
| for att in XML.children(rPr) # first copy existing attributes | ||
| for i in 1:length(atts) | ||
| if att.tag == atts[i] | ||
| if XML.tag(att) == atts[i] | ||
| new_rPr[i] = att | ||
| end | ||
| end | ||
|
|
@@ -1372,7 +1373,7 @@ function update_sharedString_font(ws::Worksheet, cell::Cell; | |
| if !isnothing(rPr.children) | ||
| empty!(rPr.children) | ||
| foreach(new_rPr) do element | ||
| element.tag != "DeleteMe" && push!(rPr.children, element) | ||
| XML.tag(element) != "DeleteMe" && push!(rPr.children, element) | ||
| end | ||
| end | ||
| end | ||
|
|
@@ -1420,7 +1421,7 @@ function update_sharedString_font(ws::Worksheet, cell::Cell; | |
| for r in 1:length(all_r) | ||
| if t[r] != ")___DeleteMe___(" # signals a merged <r> element to be skipped | ||
| write(new_r, " <r>\n") | ||
| r > inc_first && write(new_r, XML.write(rPr_elements[r-inc_first];depth=3) * "\n") | ||
| r > inc_first && write(new_r, XML.write(rPr_elements[r-inc_first]) * "\n") | ||
| write(new_r, " <t" * (needs_preserve(t[r]) ? " xml:space=\"preserve\"" : "") * ">" *t[r] * "</t>\n") | ||
| write(new_r, " </r>\n") | ||
| end | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this return
Node{SubString}?