class Xlsxrb::Ooxml::WorkbookParser::Listener
SAX listener for workbook.xml sheets, properties, and defined names.
Attributes
active_tab
[R]
untyped
code_name
[R]
untyped
date1904
[R]
untyped
defined_names
[R]
untyped
first_sheet
[R]
untyped
full_calc_on_load
[R]
untyped
sheets
[R]
untyped
show_sheet_tabs
[R]
untyped
tab_ratio
[R]
untyped
workbook_protection
[R]
untyped
Public Class Methods
() → untyped
Source
# File lib/xlsxrb/ooxml/workbook_parser.rb, line 64 def initialize @sheets = [] @date1904 = false @defined_names = [] @active_tab = nil @full_calc_on_load = nil @first_sheet = nil @show_sheet_tabs = nil @tab_ratio = nil @code_name = nil @workbook_protection = nil @in_defined_name = false @current_dn = nil @dn_text = +"" end
Public Instance Methods
(untyped text) → untyped
Source
# File lib/xlsxrb/ooxml/workbook_parser.rb, line 138 def characters(text) @dn_text << text if @in_defined_name end
(untyped _uri, untyped localname, untyped _qname) → untyped
Source
# File lib/xlsxrb/ooxml/workbook_parser.rb, line 142 def end_element(_uri, localname, _qname) return unless localname == "definedName" && @in_defined_name @current_dn[:value] = @dn_text.strip @defined_names << @current_dn @in_defined_name = false @current_dn = nil end
(untyped _uri, untyped localname, untyped _qname, untyped attrs) → untyped
Source
# File lib/xlsxrb/ooxml/workbook_parser.rb, line 80 def start_element(_uri, localname, _qname, attrs) case localname when "sheet" name_attr = attrs["name"] raw_state = attrs["state"] state_sym = case raw_state when "hidden" then :hidden when "veryHidden" then :very_hidden else :visible end @sheets << { name: name_attr, sheet_id: attrs["sheetId"]&.to_i, r_id: attrs["r:id"] || attrs["id"] || attrs.find { |k, _| k.end_with?(":id") }&.last, state: state_sym } when "workbookPr" d1904 = attrs["date1904"] @date1904 = %w[1 true].include?(d1904) unless d1904.nil? @code_name = attrs["codeName"] if attrs["codeName"] when "workbookView" at = attrs["activeTab"] @active_tab = at.to_i if at fs = attrs["firstSheet"] @first_sheet = fs.to_i if fs sst = attrs["showSheetTabs"] @show_sheet_tabs = %w[1 true].include?(sst) unless sst.nil? tr = attrs["tabRatio"] @tab_ratio = tr.to_i if tr when "calcPr" fcol = attrs["fullCalcOnLoad"] @full_calc_on_load = %w[1 true].include?(fcol) unless fcol.nil? when "workbookProtection" prot = {} attrs.each do |attr, value| key, kind = WORKBOOK_PROTECTION_ATTRIBUTES[attr] next unless key prot[key] = case kind when :bool then %w[1 true].include?(value) when :int then value.to_i else value end end @workbook_protection = prot unless prot.empty? when "definedName" @in_defined_name = true @current_dn = { name: attrs["name"], hidden: %w[1 true].include?(attrs["hidden"]) } @current_dn[:local_sheet_id] = attrs["localSheetId"].to_i if attrs["localSheetId"] @current_dn[:comment] = attrs["comment"] if attrs["comment"] @dn_text = +"" end end