class ChupaText::Decomposers::OfficeOpenXMLWorkbook::SheetListener

Constants

URI

Public Class Methods

new(sheet) click to toggle source
# File lib/chupa-text/decomposers/office-open-xml-workbook.rb, line 119
def initialize(sheet)
  @sheet = sheet
  @cell_type = nil
  @in_v = false
end

Public Instance Methods

cdata(content) click to toggle source
# File lib/chupa-text/decomposers/office-open-xml-workbook.rb, line 152
def cdata(content)
  add_column(content)
end
characters(text) click to toggle source
# File lib/chupa-text/decomposers/office-open-xml-workbook.rb, line 148
def characters(text)
  add_column(text)
end
end_element(uri, local_name, qname) click to toggle source
# File lib/chupa-text/decomposers/office-open-xml-workbook.rb, line 138
def end_element(uri, local_name, qname)
  return unless uri == URI
  case local_name
  when "c"
    @cell_type = nil
  when "v"
    @in_v = false
  end
end
start_element(uri, local_name, qname, attributes) click to toggle source
# File lib/chupa-text/decomposers/office-open-xml-workbook.rb, line 125
def start_element(uri, local_name, qname, attributes)
  return unless uri == URI
  case local_name
  when "row"
    @sheet << []
  when "c"
    @cell_type = parse_cell_type(attributes["t"])
  # when "is" # TODO
  when "v"
    @in_v = true
  end
end

Private Instance Methods

add_column(text) click to toggle source
# File lib/chupa-text/decomposers/office-open-xml-workbook.rb, line 177
def add_column(text)
  return unless @in_v
  case @cell_type
  when :shared_string
    @sheet.last << Integer(text, 10)
  else
    @sheet.last << text
  end
end
parse_cell_type(type) click to toggle source

c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_ST_CellType_topic_ID0E6NEFB.html

# File lib/chupa-text/decomposers/office-open-xml-workbook.rb, line 158
def parse_cell_type(type)
  case type
  when "b"
    :boolean
  when "e"
    :error
  when "inlineStr"
    :inline_string
  when "n"
    :number
  when "s"
    :shared_string
  when "str"
    :string
  else
    nil
  end
end