diff --git a/lib/saxlsx/shared_string_collection_parser.rb b/lib/saxlsx/shared_string_collection_parser.rb index eeb0411..9376dd0 100644 --- a/lib/saxlsx/shared_string_collection_parser.rb +++ b/lib/saxlsx/shared_string_collection_parser.rb @@ -13,22 +13,31 @@ def self.parse(file_system, &block) def initialize(&block) @block = block + @extract = false end def start_element(name) - @current_string = String.new if name == :si + case name + when :si then @current_string = nil + when :t then @extract = true + end end def end_element(name) - if name == :si - @block.call @current_string - @current_string = nil + case name + when :si then @block.call(@current_string) + when :t then @extract = false end end def text(value) - @current_string << CGI.unescapeHTML(value) if @current_string + if @extract + if @current_string + @current_string << CGI.unescapeHTML(value) + else + @current_string = CGI.unescapeHTML(value) + end + end end - end end