Class: Saxlsx::Workbook

Inherits:
Object
  • Object
show all
Defined in:
lib/saxlsx/workbook.rb

Constant Summary collapse

DATE_SYSTEM_1900 =
DateTime.new(1899, 12, 30)
DATE_SYSTEM_1904 =
DateTime.new(1904, 1, 1)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, auto_format: true) ⇒ Workbook

Returns a new instance of Workbook.



19
20
21
22
# File 'lib/saxlsx/workbook.rb', line 19

def initialize(filename, auto_format: true)
  @file_system = FileSystem.new filename
  @auto_format = auto_format
end

Instance Attribute Details

#auto_formatObject (readonly)

Returns the value of attribute auto_format.



8
9
10
# File 'lib/saxlsx/workbook.rb', line 8

def auto_format
  @auto_format
end

#date1904Object

Returns the value of attribute date1904.



7
8
9
# File 'lib/saxlsx/workbook.rb', line 7

def date1904
  @date1904
end

Class Method Details

.open(filename, **kw_args) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/saxlsx/workbook.rb', line 10

def self.open(filename, **kw_args)
  begin
    workbook = new(filename, **kw_args)
    yield workbook
  ensure
    workbook.close if workbook
  end
end

Instance Method Details

#base_dateObject



45
46
47
# File 'lib/saxlsx/workbook.rb', line 45

def base_date
  @base_date ||= date1904 ? DATE_SYSTEM_1904 : DATE_SYSTEM_1900
end

#closeObject



24
25
26
# File 'lib/saxlsx/workbook.rb', line 24

def close
  @file_system.close
end

#number_formatsObject



41
42
43
# File 'lib/saxlsx/workbook.rb', line 41

def number_formats
  @number_formats ||= StyleCollection.new(@file_system).to_a
end

#shared_stringsObject



37
38
39
# File 'lib/saxlsx/workbook.rb', line 37

def shared_strings
  @shared_strings ||= SharedStringCollection.new(@file_system).to_a
end

#sheet_namesObject



33
34
35
# File 'lib/saxlsx/workbook.rb', line 33

def sheet_names
  sheets.map(&:name)
end

#sheets(name = nil) ⇒ Object



28
29
30
31
# File 'lib/saxlsx/workbook.rb', line 28

def sheets(name=nil)
  @sheets ||= SheetCollection.new(@file_system, self).to_a
  name.nil? ? @sheets : @sheets.detect { |s| s.name == name }
end

#to_csv(path) ⇒ Object



49
50
51
# File 'lib/saxlsx/workbook.rb', line 49

def to_csv(path)
  sheets.each { |s| s.to_csv path }
end