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) ⇒ Workbook

Returns a new instance of Workbook.



17
18
19
# File 'lib/saxlsx/workbook.rb', line 17

def initialize(filename)
  @file_system = FileSystem.new filename
end

Instance Attribute Details

#date1904Object

Returns the value of attribute date1904.



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

def date1904
  @date1904
end

Class Method Details

.open(filename) ⇒ Object



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

def self.open(filename)
  begin
    workbook = self.new(filename)
    yield workbook
  ensure
    workbook.close
  end
end

Instance Method Details

#base_dateObject



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

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

#closeObject



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

def close
  @file_system.close
end

#number_formatsObject



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

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

#shared_stringsObject



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

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

#sheet_namesObject



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

def sheet_names
  sheets.map(&:name)
end

#sheets(name = nil) ⇒ Object



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

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



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

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