Class: Saxlsx::Sheet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, index, file_system, workbook) ⇒ Sheet

Returns a new instance of Sheet.



7
8
9
10
11
12
# File 'lib/saxlsx/sheet.rb', line 7

def initialize(name, index, file_system, workbook)
  @name = name
  @index = index
  @file_system = file_system
  @workbook = workbook
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/saxlsx/sheet.rb', line 5

def name
  @name
end

Instance Method Details

#rowsObject



14
15
16
# File 'lib/saxlsx/sheet.rb', line 14

def rows
  @rows ||= RowsCollection.new(@index, @file_system, @workbook)
end

#to_csv(path) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/saxlsx/sheet.rb', line 18

def to_csv(path)
  FileUtils.mkpath path unless Dir.exists? path
  File.open("#{path}/#{name}.csv", 'w') do |f|
    rows.each do |row|
      f.puts row.map{|c| "\"#{c}\""}.join(',')
    end
  end
end