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.



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

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.



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

def name
  @name
end

Instance Method Details

#rowsObject



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

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

#to_csv(path) ⇒ Object



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

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