class Creeker::Book

Constants

DATE_1900
DATE_1904

Attributes

files[R]
shared_strings[R]
sheets[R]

Public Class Methods

new(path, options = {}) click to toggle source
# File lib/creeker/book.rb, line 17
def initialize path, options = {}
  check_file_extension = options.fetch(:check_file_extension, true)
  if check_file_extension
    extension = File.extname(options[:original_filename] || path).downcase
    raise 'Not a valid file format.' unless (['.xlsx', '.xlsm'].include? extension)
  end
  if options[:remote]
    zipfile = Tempfile.new("file")
    zipfile.binmode
    zipfile.write(HTTParty.get(path).body)
    zipfile.close
    path = zipfile.path
  end

  @files = Zip::File.open(path)
  @shared_strings = SharedStrings.new(self, options[:multi_thread])
end

Public Instance Methods

base_date() click to toggle source
# File lib/creeker/book.rb, line 63
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_1900 # default

    doc = @files.file.open "xl/workbook.xml"
    xml = Nokogiri::XML::Document.parse doc
    xml.css('workbookPr[date1904]').each do |workbookPr|
      if workbookPr['date1904'] =~ /true|1/i
        result = DATE_1904
        break
      end
    end

    result
  end
end
close() click to toggle source
# File lib/creeker/book.rb, line 59
def close
  @files.close
end
style_types() click to toggle source
# File lib/creeker/book.rb, line 55
def style_types
  @style_types ||= Creeker::Styles.new(self).style_types
end