Class: Saxlsx::Workbook
- Inherits:
-
Object
- Object
- Saxlsx::Workbook
- 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
-
#date1904 ⇒ Object
Returns the value of attribute date1904.
Class Method Summary collapse
Instance Method Summary collapse
- #base_date ⇒ Object
- #close ⇒ Object
-
#initialize(filename) ⇒ Workbook
constructor
A new instance of Workbook.
- #number_formats ⇒ Object
- #shared_strings ⇒ Object
- #sheet_names ⇒ Object
- #sheets(name = nil) ⇒ Object
- #to_csv(path) ⇒ Object
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
#date1904 ⇒ Object
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_date ⇒ Object
42 43 44 |
# File 'lib/saxlsx/workbook.rb', line 42 def base_date @base_date ||= date1904 ? DATE_SYSTEM_1904 : DATE_SYSTEM_1900 end |
#close ⇒ Object
21 22 23 |
# File 'lib/saxlsx/workbook.rb', line 21 def close @file_system.close end |
#number_formats ⇒ Object
38 39 40 |
# File 'lib/saxlsx/workbook.rb', line 38 def number_formats @number_formats ||= StyleCollection.new(@file_system).to_a end |
#shared_strings ⇒ Object
34 35 36 |
# File 'lib/saxlsx/workbook.rb', line 34 def shared_strings @shared_strings ||= SharedStringCollection.new(@file_system).to_a end |
#sheet_names ⇒ Object
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 |