Class: Workbook::Sheet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table = Workbook::Table.new([], self), book = nil, options = {}) ⇒ Workbook::Sheet

Initialize a new sheet

Parameters:

  • table (Workbook::Table, Array<Array>) (defaults to: Workbook::Table.new([], self))

    The first table of this sheet

  • book (Workbook::Book) (defaults to: nil)

    The book this sheet belongs to

  • options (Hash) (defaults to: {})

    are forwarded to Workbook::Table.new



13
14
15
16
17
18
19
20
21
# File 'lib/workbook/sheet.rb', line 13

def initialize table=Workbook::Table.new([], self), book=nil, options={}
  if table.is_a? Workbook::Table
    push table
  else
    push Workbook::Table.new(table, self, options)
  end
  self.book = book
  return self
end

Instance Attribute Details

#nameObject

A Sheet is a container of tables



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

def name
  @name
end

Instance Method Details

#bookWorkbook::Book

Returns the book this sheet belongs to

Returns:



57
58
59
60
61
62
63
64
# File 'lib/workbook/sheet.rb', line 57

def book
  if @book
    return @book
  else
    self.book = Workbook::Book.new(self)
    return @book
  end
end

#book=(b) ⇒ Object



66
67
68
# File 'lib/workbook/sheet.rb', line 66

def book= b
  @book = b
end

#cloneWorkbook::Sheet

clones itself and the tables it contains

Returns:



80
81
82
83
84
85
86
# File 'lib/workbook/sheet.rb', line 80

def clone
  s = self
  c = super
  c.delete_all
  s.each{|t| c << t.clone}
  return c
end

#create_or_open_table_at(index) ⇒ Object

Create or open the existing table at an index value

Parameters:

  • index (Integer)

    the index of the table



91
92
93
94
95
96
# File 'lib/workbook/sheet.rb', line 91

def create_or_open_table_at index
  t = self[index]
  t = self[index] = Workbook::Table.new if t == nil
  t.sheet = self
  t
end

#delete_allWorkbook::Table

Removes all lines from this table

Returns:



73
74
75
# File 'lib/workbook/sheet.rb', line 73

def delete_all
  self.delete_if{|b| true}
end

#has_contents?Boolean

Returns true if the first table of this sheet contains anything

Returns:

  • (Boolean)


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

def has_contents?
  table.has_contents?
end

#tableWorkbook::Table

Returns the first table of this sheet

Returns:



33
34
35
# File 'lib/workbook/sheet.rb', line 33

def table
  first
end

#table=(table, options = {}) ⇒ Workbook::Table

Set the first table of this sheet with a table or array of cells/values

Parameters:

  • table (Workbook::Table, Array<Array>)

    The new first table of this sheet

  • options (Hash) (defaults to: {})

    are forwarded to Workbook::Table.new

Returns:



45
46
47
48
49
50
51
52
# File 'lib/workbook/sheet.rb', line 45

def table= table, options={}
  if table.is_a? Workbook::Table
    self[0] = table
  else
    self[0] = Workbook::Table.new(table, self, options)
  end
  return table
end