class Xlsxrb::Ooxml::Reader::WorkbookListener
SAX2 listener for parsing workbook.xml to discover sheet names, rIds, and workbook-level properties.
Attributes
Public Class Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 1980 def initialize @sheets = [] @workbook_properties = {} @workbook_views = {} @calc_properties = {} @file_recovery_properties = {} @defined_names = [] @workbook_protection = nil @file_version = {} @file_sharing = {} @conformance = nil @inside_defined_name = false @current_dn_attrs = nil @dn_text_buffer = +"" end
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 2186 def characters(text) @dn_text_buffer << text if @inside_defined_name end
# File lib/xlsxrb/ooxml/reader.rb, line 2190 def end_element(_uri, local_name, qname) name = element_name(local_name, qname) return unless name == "definedName" && @inside_defined_name @current_dn_attrs[:value] = @dn_text_buffer.dup @defined_names << @current_dn_attrs @inside_defined_name = false @current_dn_attrs = nil end
# File lib/xlsxrb/ooxml/reader.rb, line 1996 def start_element(_uri, local_name, qname, attributes) name = element_name(local_name, qname) case name when "workbook" @conformance = attributes["conformance"] if attributes["conformance"] when "sheet" @sheets << { name: attributes["name"], rid: attributes["r:id"], state: attributes["state"] } when "fileVersion" an = attributes["appName"] @file_version[:app_name] = an if an le = attributes["lastEdited"] @file_version[:last_edited] = le if le loe = attributes["lowestEdited"] @file_version[:lowest_edited] = loe if loe rb = attributes["rupBuild"] @file_version[:rup_build] = rb if rb cn = attributes["codeName"] @file_version[:code_name] = cn if cn when "fileSharing" @file_sharing[:read_only_recommended] = true if %w[1 true].include?(attributes["readOnlyRecommended"]) un = attributes["userName"] @file_sharing[:user_name] = un if un an = attributes["algorithmName"] @file_sharing[:algorithm_name] = an if an hv = attributes["hashValue"] @file_sharing[:hash_value] = hv if hv sv = attributes["saltValue"] @file_sharing[:salt_value] = sv if sv sc = attributes["spinCount"] @file_sharing[:spin_count] = sc.to_i if sc when "workbookPr" d1904 = attributes["date1904"] @workbook_properties[:date1904] = %w[1 true].include?(d1904) unless d1904.nil? dtv = attributes["defaultThemeVersion"] @workbook_properties[:default_theme_version] = dtv.to_i if dtv cn = attributes["codeName"] @workbook_properties[:code_name] = cn if cn fp = attributes["filterPrivacy"] @workbook_properties[:filter_privacy] = %w[1 true].include?(fp) unless fp.nil? acp = attributes["autoCompressPictures"] @workbook_properties[:auto_compress_pictures] = %w[1 true].include?(acp) unless acp.nil? bf = attributes["backupFile"] @workbook_properties[:backup_file] = %w[1 true].include?(bf) unless bf.nil? so = attributes["showObjects"] @workbook_properties[:show_objects] = so if so ul = attributes["updateLinks"] @workbook_properties[:update_links] = ul if ul rac = attributes["refreshAllConnections"] @workbook_properties[:refresh_all_connections] = %w[1 true].include?(rac) unless rac.nil? cc = attributes["checkCompatibility"] @workbook_properties[:check_compatibility] = %w[1 true].include?(cc) unless cc.nil? hpfl = attributes["hidePivotFieldList"] @workbook_properties[:hide_pivot_field_list] = %w[1 true].include?(hpfl) unless hpfl.nil? sbut = attributes["showBorderUnselectedTables"] @workbook_properties[:show_border_unselected_tables] = %w[1 true].include?(sbut) unless sbut.nil? ps = attributes["promptedSolutions"] @workbook_properties[:prompted_solutions] = %w[1 true].include?(ps) unless ps.nil? sia = attributes["showInkAnnotation"] @workbook_properties[:show_ink_annotation] = %w[1 true].include?(sia) unless sia.nil? selv = attributes["saveExternalLinkValues"] @workbook_properties[:save_external_link_values] = %w[1 true].include?(selv) unless selv.nil? spcf = attributes["showPivotChartFilter"] @workbook_properties[:show_pivot_chart_filter] = %w[1 true].include?(spcf) unless spcf.nil? arq = attributes["allowRefreshQuery"] @workbook_properties[:allow_refresh_query] = %w[1 true].include?(arq) unless arq.nil? pi = attributes["publishItems"] @workbook_properties[:publish_items] = %w[1 true].include?(pi) unless pi.nil? dcompat = attributes["dateCompatibility"] @workbook_properties[:date_compatibility] = %w[1 true].include?(dcompat) unless dcompat.nil? when "workbookView" at = attributes["activeTab"] @workbook_views[:active_tab] = at.to_i if at fs = attributes["firstSheet"] @workbook_views[:first_sheet] = fs.to_i if fs vis = attributes["visibility"] @workbook_views[:visibility] = vis if vis min = attributes["minimized"] @workbook_views[:minimized] = %w[1 true].include?(min) unless min.nil? shs = attributes["showHorizontalScroll"] @workbook_views[:show_horizontal_scroll] = %w[1 true].include?(shs) unless shs.nil? svs = attributes["showVerticalScroll"] @workbook_views[:show_vertical_scroll] = %w[1 true].include?(svs) unless svs.nil? sst = attributes["showSheetTabs"] @workbook_views[:show_sheet_tabs] = %w[1 true].include?(sst) unless sst.nil? xw = attributes["xWindow"] @workbook_views[:x_window] = xw.to_i if xw yw = attributes["yWindow"] @workbook_views[:y_window] = yw.to_i if yw ww = attributes["windowWidth"] @workbook_views[:window_width] = ww.to_i if ww wh = attributes["windowHeight"] @workbook_views[:window_height] = wh.to_i if wh tr = attributes["tabRatio"] @workbook_views[:tab_ratio] = tr.to_i if tr afdg = attributes["autoFilterDateGrouping"] @workbook_views[:auto_filter_date_grouping] = %w[1 true].include?(afdg) unless afdg.nil? when "calcPr" ci = attributes["calcId"] @calc_properties[:calc_id] = ci.to_i if ci cm = attributes["calcMode"] @calc_properties[:calc_mode] = cm if cm fcol = attributes["fullCalcOnLoad"] @calc_properties[:full_calc_on_load] = %w[1 true].include?(fcol) unless fcol.nil? iter = attributes["iterate"] @calc_properties[:iterate] = %w[1 true].include?(iter) unless iter.nil? ic = attributes["iterateCount"] @calc_properties[:iterate_count] = ic.to_i if ic id = attributes["iterateDelta"] @calc_properties[:iterate_delta] = id.to_f if id rm = attributes["refMode"] @calc_properties[:ref_mode] = rm if rm cc = attributes["calcCompleted"] @calc_properties[:calc_completed] = %w[1 true].include?(cc) unless cc.nil? cos = attributes["calcOnSave"] @calc_properties[:calc_on_save] = %w[1 true].include?(cos) unless cos.nil? fprec = attributes["fullPrecision"] @calc_properties[:full_precision] = %w[1 true].include?(fprec) unless fprec.nil? conc = attributes["concurrentCalc"] @calc_properties[:concurrent_calc] = %w[1 true].include?(conc) unless conc.nil? cmc = attributes["concurrentManualCount"] @calc_properties[:concurrent_manual_count] = cmc.to_i if cmc ffc = attributes["forceFullCalc"] @calc_properties[:force_full_calc] = %w[1 true].include?(ffc) unless ffc.nil? when "fileRecoveryPr" ar = attributes["autoRecover"] @file_recovery_properties[:auto_recover] = %w[1 true].include?(ar) unless ar.nil? cs = attributes["crashSave"] @file_recovery_properties[:crash_save] = %w[1 true].include?(cs) unless cs.nil? del = attributes["dataExtractLoad"] @file_recovery_properties[:data_extract_load] = %w[1 true].include?(del) unless del.nil? rl = attributes["repairLoad"] @file_recovery_properties[:repair_load] = %w[1 true].include?(rl) unless rl.nil? when "workbookProtection" prot = {} ls = attributes["lockStructure"] prot[:lock_structure] = %w[1 true].include?(ls) unless ls.nil? lw = attributes["lockWindows"] prot[:lock_windows] = %w[1 true].include?(lw) unless lw.nil? lr = attributes["lockRevision"] prot[:lock_revision] = %w[1 true].include?(lr) unless lr.nil? wp = attributes["workbookPassword"] prot[:password] = wp if wp an = attributes["workbookAlgorithmName"] if an prot[:algorithm_name] = an hv = attributes["workbookHashValue"] prot[:hash_value] = hv if hv sv = attributes["workbookSaltValue"] prot[:salt_value] = sv if sv sc = attributes["workbookSpinCount"] prot[:spin_count] = sc.to_i if sc end ran = attributes["revisionsAlgorithmName"] if ran prot[:revisions_algorithm_name] = ran rhv = attributes["revisionsHashValue"] prot[:revisions_hash_value] = rhv if rhv rsv = attributes["revisionsSaltValue"] prot[:revisions_salt_value] = rsv if rsv rsc = attributes["revisionsSpinCount"] prot[:revisions_spin_count] = rsc.to_i if rsc end rp = attributes["revisionsPassword"] prot[:revisions_password] = rp if rp @workbook_protection = prot unless prot.empty? when "definedName" @inside_defined_name = true @current_dn_attrs = { name: attributes["name"], hidden: %w[1 true].include?(attributes["hidden"]) } lsi = attributes["localSheetId"] @current_dn_attrs[:local_sheet_id] = lsi.to_i if lsi @current_dn_attrs[:comment] = attributes["comment"] if attributes["comment"] @current_dn_attrs[:description] = attributes["description"] if attributes["description"] @current_dn_attrs[:function] = true if %w[1 true].include?(attributes["function"]) @current_dn_attrs[:vb_procedure] = true if %w[1 true].include?(attributes["vbProcedure"]) @current_dn_attrs[:xlm] = true if %w[1 true].include?(attributes["xlm"]) @current_dn_attrs[:shortcut_key] = attributes["shortcutKey"] if attributes["shortcutKey"] @current_dn_attrs[:publish_to_server] = true if %w[1 true].include?(attributes["publishToServer"]) @current_dn_attrs[:workbook_parameter] = true if %w[1 true].include?(attributes["workbookParameter"]) fgi = attributes["functionGroupId"] @current_dn_attrs[:function_group_id] = fgi.to_i if fgi @current_dn_attrs[:custom_menu] = attributes["customMenu"] if attributes["customMenu"] @current_dn_attrs[:help] = attributes["help"] if attributes["help"] @current_dn_attrs[:status_bar] = attributes["statusBar"] if attributes["statusBar"] @dn_text_buffer = +"" end end