class Xlsxrb::Ooxml::StylesParser::Listener
SAX listener for parsing styles.xml content.
Attributes
Public Class Methods
Source
# File lib/xlsxrb/ooxml/styles_parser.rb, line 24 def initialize @result = { num_fmts: {}, fonts: [], fills: [], borders: [], cell_xfs: [], cell_style_xfs: [] } @context = [] @current_font = nil @current_fill = nil @current_fill_pattern = nil @current_border = nil @current_xf = nil @in_cell_xfs = false @in_cell_style_xfs = false end
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/styles_parser.rb, line 114 def characters(_text) # No text content needed for styles end
# File lib/xlsxrb/ooxml/styles_parser.rb, line 85 def end_element(_uri, localname, _qname) case localname when "font" if @current_font @result[:fonts] << @current_font @current_font = nil end when "fill" if @current_fill @current_fill[:pattern] = @current_fill_pattern if @current_fill_pattern @result[:fills] << @current_fill @current_fill = nil @current_fill_pattern = nil end when "border" if @current_border @result[:borders] << @current_border @current_border = nil end when "cellXfs" @in_cell_xfs = false when "cellStyleXfs" @in_cell_style_xfs = false when "xf" finalize_xf end @context.pop end
# File lib/xlsxrb/ooxml/styles_parser.rb, line 43 def start_element(_uri, localname, _qname, attrs) @context.push(localname) case localname when "numFmt" id = attrs["numFmtId"]&.to_i code = attrs["formatCode"] @result[:num_fmts][id] = code if id && code when "font" @current_font = {} if parent_context?("fonts") when "b" @current_font[:bold] = true if @current_font when "i" @current_font[:italic] = true if @current_font when "u" @current_font[:underline] = attrs["val"] || "single" if @current_font when "sz" @current_font[:sz] = attrs["val"]&.to_f if @current_font when "color" handle_color(attrs) when "name" @current_font[:name] = attrs["val"] if @current_font when "fill" @current_fill = {} if parent_context?("fills") when "patternFill" @current_fill_pattern = attrs["patternType"] if @current_fill when "fgColor", "bgColor" handle_fill_color(localname, attrs) if @current_fill when "border" @current_border = {} if parent_context?("borders") when "left", "right", "top", "bottom", "diagonal" handle_border_side(localname, attrs) when "cellXfs" @in_cell_xfs = true when "cellStyleXfs" @in_cell_style_xfs = true when "xf" handle_xf(attrs) when "alignment" handle_alignment(attrs) end end