Class: XLSX::Workbook

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorkbook

create a new work book



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

def initialize
  @sheets = Array.new
  @strings = Array.new
end

Instance Attribute Details

#sheetsObject

an array of all the sheets in this workbook.



4
5
6
# File 'lib/xlsx/workbook.rb', line 4

def sheets
  @sheets
end

#stringsObject

:nodoc:



5
6
7
# File 'lib/xlsx/workbook.rb', line 5

def strings
  @strings
end

Instance Method Details

#add_sheet(name) {|sheet| ... } ⇒ Object

Add a new sheet with name.

Yields:

  • (sheet)


14
15
16
17
18
19
20
21
22
23
# File 'lib/xlsx/workbook.rb', line 14

def add_sheet(name)
  sheet = Sheet.new
  @sheets.push(sheet)
  sheet.id = @sheets.size
  sheet.name = name
  sheet.hash = Digest::SHA1.hexdigest("#{name}--#{sheet.id}")
  sheet.workbook = self
  yield(sheet) if block_given?
  sheet
end

#buildObject

Get the data.



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

def build
  ::XLSX::Formatter.build(self)
end

#dump(path = nil) ⇒ Object

Write the data to an .xlsx file



31
32
33
# File 'lib/xlsx/workbook.rb', line 31

def dump(path=nil)
  ::XLSX::Formatter.dump(self, path)
end

#register_string(string) ⇒ Object

:nodoc:



35
36
37
38
39
40
41
42
# File 'lib/xlsx/workbook.rb', line 35

def register_string(string) # :nodoc:
  index = @strings.index(string)
  if index.nil?
    index = @strings.size
    @strings.push string
  end
  index
end