PPTX.jl
PPTX.jl copied to clipboard
Referring to slide layouts by name
At the moment (v0.6) PPTX.Slide
argument for layout is defined like layout::Int=1
ie as an integer.
For convenience, would be nice to be able to refer to the layout by name as well.
Code sketch to extract name to number map
layoutnamemap = Dict{String,Int}()
layouts = readdir(raw"ppt/slideLayouts", join=true)
for layout in layouts
m = match(r"slideLayout(?<id>\d*).xml$", layout)
isnothing(m) && continue
id = parse(Int, m[:id])
doc = readxml(layout)
r = root(doc)
n = findfirst("//p:cSld", r)
push!(layoutnamemap, n["name"] => id)
end
I agree this would be more intuitive to users.
Quick brainstorm
- Make the Slide.layout field a
Union{Integer, String}
. - Upon writing the PPTX, create this
layoutnamemap
. - Pass this
layoutnamemap
throughwrite_slides!
to themake_slide_relationships
function - create something like:
id = get_slide_layout_id(s::Slide, layoutnamemap)
I wonder if we should make this layoutnamemap
a property of the Presentation
, since it's kinda part of the global state of the presentation.