class Xlsxrb::Ooxml::Reader::TableListener
SAX2 listener for parsing table XML.
Attributes
Public Class Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 4081 def initialize @table = nil @columns = [] @current_column = nil @inside_calc_formula = false @inside_totals_formula = false @text_buffer = +"" end
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 4163 def characters(text) @text_buffer << text if @inside_calc_formula || @inside_totals_formula end
# File lib/xlsxrb/ooxml/reader.rb, line 4167 def end_element(_uri, local_name, qname) name = element_name(local_name, qname) case name when "calculatedColumnFormula" @current_column[:calculated_column_formula] = @text_buffer.dup if @current_column @inside_calc_formula = false when "totalsRowFormula" @current_column[:totals_row_formula] = @text_buffer.dup if @current_column @inside_totals_formula = false when "tableColumn" @columns << @current_column if @current_column @current_column = nil when "table" @table[:columns] = @columns if @table end end
# File lib/xlsxrb/ooxml/reader.rb, line 4090 def start_element(_uri, local_name, qname, attributes) name = element_name(local_name, qname) case name when "table" @table = { id: attributes["id"]&.to_i, name: attributes["name"], display_name: attributes["displayName"], ref: attributes["ref"] } trc = attributes["totalsRowCount"] @table[:totals_row_count] = trc.to_i if trc hrc = attributes["headerRowCount"] @table[:header_row_count] = hrc.to_i if hrc @table[:published] = true if attributes["published"] == "1" @table[:comment] = attributes["comment"] if attributes["comment"] @table[:insert_row] = true if attributes["insertRow"] == "1" @table[:insert_row_shift] = true if attributes["insertRowShift"] == "1" hrd = attributes["headerRowDxfId"] @table[:header_row_dxf_id] = hrd.to_i if hrd dd = attributes["dataDxfId"] @table[:data_dxf_id] = dd.to_i if dd trd = attributes["totalsRowDxfId"] @table[:totals_row_dxf_id] = trd.to_i if trd hrbd = attributes["headerRowBorderDxfId"] @table[:header_row_border_dxf_id] = hrbd.to_i if hrbd tbd = attributes["tableBorderDxfId"] @table[:table_border_dxf_id] = tbd.to_i if tbd trbd = attributes["totalsRowBorderDxfId"] @table[:totals_row_border_dxf_id] = trbd.to_i if trbd @table[:header_row_cell_style] = attributes["headerRowCellStyle"] if attributes["headerRowCellStyle"] @table[:totals_row_cell_style] = attributes["totalsRowCellStyle"] if attributes["totalsRowCellStyle"] cid = attributes["connectionId"] @table[:connection_id] = cid.to_i if cid @table[:table_type] = attributes["tableType"] if attributes["tableType"] when "tableColumn" col = { name: attributes["name"] } trf = attributes["totalsRowFunction"] col[:totals_row_function] = trf if trf trl = attributes["totalsRowLabel"] col[:totals_row_label] = trl if trl dd = attributes["dataDxfId"] col[:data_dxf_id] = dd.to_i if dd td = attributes["totalsRowDxfId"] col[:totals_row_dxf_id] = td.to_i if td hd = attributes["headerRowDxfId"] col[:header_row_dxf_id] = hd.to_i if hd dcs = attributes["dataCellStyle"] col[:data_cell_style] = dcs if dcs @current_column = col when "calculatedColumnFormula" @inside_calc_formula = true @text_buffer = +"" when "totalsRowFormula" @inside_totals_formula = true @text_buffer = +"" when "tableStyleInfo" if @table si = {} si[:name] = attributes["name"] if attributes["name"] sfc = attributes["showFirstColumn"] si[:show_first_column] = sfc == "1" unless sfc.nil? slc = attributes["showLastColumn"] si[:show_last_column] = slc == "1" unless slc.nil? srs = attributes["showRowStripes"] si[:show_row_stripes] = srs == "1" unless srs.nil? scs = attributes["showColumnStripes"] si[:show_column_stripes] = scs == "1" unless scs.nil? @table[:style] = si end end end