class Xlsxrb::Ooxml::Reader::SharedStringsListener
SAX2 listener for parsing shared string table (xl/sharedStrings.xml).
Attributes
Public Class Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 1615 def initialize @strings = [] @inside_si = false @inside_r = false @inside_rpr = false @inside_t = false @text_buffer = +"" @runs = [] @current_font = {} @has_runs = false end
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 1680 def characters(text) @text_buffer << text if @inside_t end
# File lib/xlsxrb/ooxml/reader.rb, line 1684 def end_element(_uri, local_name, qname) name = element_name(local_name, qname) case name when "t" @inside_t = false when "rPr" @inside_rpr = false when "r" run = { text: @text_buffer.dup } run[:font] = @current_font.dup unless @current_font.empty? @runs << run @inside_r = false when "si" @strings << if @has_runs Xlsxrb::Elements::RichText.new(runs: @runs) else @text_buffer.dup end @inside_si = false @text_buffer = +"" @runs = [] end end
# File lib/xlsxrb/ooxml/reader.rb, line 1627 def start_element(_uri, local_name, qname, attributes) name = element_name(local_name, qname) case name when "si" @inside_si = true @text_buffer = +"" @runs = [] @has_runs = false when "r" @inside_r = true @has_runs = true @current_font = {} when "rPr" @inside_rpr = true if @inside_r when "b" @current_font[:bold] = true if @inside_rpr when "i" @current_font[:italic] = true if @inside_rpr when "strike" @current_font[:strike] = true if @inside_rpr when "u" if @inside_rpr val = attributes["val"] @current_font[:underline] = val || true end when "vertAlign" @current_font[:vert_align] = attributes["val"] if @inside_rpr && attributes["val"] when "sz" @current_font[:sz] = attributes["val"]&.to_f if @inside_rpr when "color" if @inside_rpr if attributes["rgb"] @current_font[:color] = attributes["rgb"] elsif attributes["theme"] @current_font[:theme] = attributes["theme"].to_i @current_font[:tint] = attributes["tint"].to_f if attributes["tint"] elsif attributes["indexed"] @current_font[:indexed] = attributes["indexed"].to_i end end when "rFont" @current_font[:name] = attributes["val"] if @inside_rpr when "family" @current_font[:family] = attributes["val"]&.to_i if @inside_rpr when "scheme" @current_font[:scheme] = attributes["val"] if @inside_rpr when "t" @inside_t = @inside_si @text_buffer = +"" if @inside_r end end