class Xlsxrb::Ooxml::Reader::PrintPageListener
SAX2 listener for parsing print/page elements from worksheet XML.
Attributes
Public Class Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 3927 def initialize @print_options = {} @page_margins = nil @page_setup = {} @header_footer = {} @row_breaks = [] @col_breaks = [] @inside_header_footer = false @inside_row_breaks = false @inside_col_breaks = false @current_hf_field = nil @text_buffer = +"" end
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 4030 def characters(text) @text_buffer << text if @current_hf_field end
# File lib/xlsxrb/ooxml/reader.rb, line 4034 def end_element(_uri, local_name, qname) name = element_name(local_name, qname) case name when "headerFooter" @inside_header_footer = false when "oddHeader" @header_footer[:odd_header] = @text_buffer.dup if @current_hf_field == "oddHeader" @current_hf_field = nil when "oddFooter" @header_footer[:odd_footer] = @text_buffer.dup if @current_hf_field == "oddFooter" @current_hf_field = nil when "evenHeader" @header_footer[:even_header] = @text_buffer.dup if @current_hf_field == "evenHeader" @current_hf_field = nil when "evenFooter" @header_footer[:even_footer] = @text_buffer.dup if @current_hf_field == "evenFooter" @current_hf_field = nil when "firstHeader" @header_footer[:first_header] = @text_buffer.dup if @current_hf_field == "firstHeader" @current_hf_field = nil when "firstFooter" @header_footer[:first_footer] = @text_buffer.dup if @current_hf_field == "firstFooter" @current_hf_field = nil when "rowBreaks" @inside_row_breaks = false when "colBreaks" @inside_col_breaks = false end end
# File lib/xlsxrb/ooxml/reader.rb, line 3941 def start_element(_uri, local_name, qname, attributes) name = element_name(local_name, qname) case name when "printOptions" @print_options[:grid_lines] = true if attributes["gridLines"] == "1" @print_options[:headings] = true if attributes["headings"] == "1" @print_options[:horizontal_centered] = true if attributes["horizontalCentered"] == "1" @print_options[:vertical_centered] = true if attributes["verticalCentered"] == "1" gls = attributes["gridLinesSet"] @print_options[:grid_lines_set] = gls != "0" if gls when "pageMargins" m = {} %w[left right top bottom header footer].each do |k| v = attributes[k] m[k.to_sym] = v.to_f if v end @page_margins = m unless m.empty? when "pageSetup" o = attributes["orientation"] @page_setup[:orientation] = o if o ps = attributes["paperSize"] @page_setup[:paper_size] = ps.to_i if ps sc = attributes["scale"] @page_setup[:scale] = sc.to_i if sc ftw = attributes["fitToWidth"] @page_setup[:fit_to_width] = ftw.to_i if ftw fth = attributes["fitToHeight"] @page_setup[:fit_to_height] = fth.to_i if fth po = attributes["pageOrder"] @page_setup[:page_order] = po if po baw = attributes["blackAndWhite"] @page_setup[:black_and_white] = true if %w[1 true].include?(baw) dr = attributes["draft"] @page_setup[:draft] = true if %w[1 true].include?(dr) cc = attributes["cellComments"] @page_setup[:cell_comments] = cc if cc fpn = attributes["firstPageNumber"] @page_setup[:first_page_number] = fpn.to_i if fpn ufpn = attributes["useFirstPageNumber"] @page_setup[:use_first_page_number] = true if %w[1 true].include?(ufpn) hdpi = attributes["horizontalDpi"] @page_setup[:horizontal_dpi] = hdpi.to_i if hdpi vdpi = attributes["verticalDpi"] @page_setup[:vertical_dpi] = vdpi.to_i if vdpi cp = attributes["copies"] @page_setup[:copies] = cp.to_i if cp ph = attributes["paperHeight"] @page_setup[:paper_height] = ph if ph pw = attributes["paperWidth"] @page_setup[:paper_width] = pw if pw err = attributes["errors"] @page_setup[:errors] = err if err upd = attributes["usePrinterDefaults"] @page_setup[:use_printer_defaults] = %w[1 true].include?(upd) unless upd.nil? when "headerFooter" @inside_header_footer = true df = attributes["differentFirst"] @header_footer[:different_first] = true if %w[1 true].include?(df) doe = attributes["differentOddEven"] @header_footer[:different_odd_even] = true if %w[1 true].include?(doe) swd = attributes["scaleWithDoc"] @header_footer[:scale_with_doc] = swd != "0" if swd awm = attributes["alignWithMargins"] @header_footer[:align_with_margins] = awm != "0" if awm when "oddHeader", "oddFooter", "evenHeader", "evenFooter", "firstHeader", "firstFooter" if @inside_header_footer @current_hf_field = name @text_buffer = +"" end when "rowBreaks" @inside_row_breaks = true when "colBreaks" @inside_col_breaks = true when "brk" id = attributes["id"]&.to_i if id brk = { id: id } mn = attributes["min"] brk[:min] = mn.to_i if mn mx = attributes["max"] brk[:max] = mx.to_i if mx brk[:man] = true if %w[1 true].include?(attributes["man"]) brk[:pt] = true if %w[1 true].include?(attributes["pt"]) @row_breaks << brk if @inside_row_breaks @col_breaks << brk if @inside_col_breaks end end end