class Roo::Excelx::Workbook

Public Class Methods

new(path) click to toggle source
Calls superclass method Roo::Excelx::Extractor::new
# File lib/roo/excelx/workbook.rb, line 20
def initialize(path)
  super
  if !doc_exists?
    raise ArgumentError, 'missing required workbook file'
  end
end

Public Instance Methods

base_date() click to toggle source
# File lib/roo/excelx/workbook.rb, line 42
def base_date
  @base_date ||=
    begin
      # Default to 1900 (minus one day due to excel quirk) but use 1904 if
      # it's set in the Workbook's workbookPr
      # http://msdn.microsoft.com/en-us/library/ff530155(v=office.12).aspx
      result = Date.new(1899,12,30) # default
      doc.css("workbookPr[date1904]").each do |workbookPr|
        if workbookPr["date1904"] =~ /true|1/i
          result = Date.new(1904,01,01)
          break
        end
      end
      result
    end
end
defined_names() click to toggle source

aka labels

# File lib/roo/excelx/workbook.rb, line 32
def defined_names
  Hash[doc.xpath("//definedName").map do |defined_name|
    # "Sheet1!$C$5"
    sheet, coordinates = defined_name.text.split('!$', 2)
    col,row = coordinates.split('$')
    name = defined_name['name']
    [name, Label.new(name, sheet,row,col)]
  end]
end
sheets() click to toggle source
# File lib/roo/excelx/workbook.rb, line 27
def sheets
  doc.xpath("//sheet")
end