Class: Spreadsheet::Excel::Worksheet

Inherits:
Worksheet
  • Object
show all
Includes:
Offset
Defined in:
lib/spreadsheet/excel/worksheet.rb

Overview

to use any of these.

Instance Attribute Summary collapse

Attributes included from Offset

#changes, #offsets

Attributes inherited from Worksheet

#columns, #fit_height_to_pages, #fit_width_to_pages, #name, #orientation, #rows, #selected, #workbook

Instance Method Summary collapse

Methods included from Offset

append_features

Methods included from Compatibility

#ivar_name, #method_name

Methods inherited from Worksheet

#[], #[]=, #active, #active=, #add_format, #cell, #column_count, #column_updated, #default_format, #default_format=, #delete_row, #dimensions, #encoding, #format_column, #format_dates!, #insert_row, #inspect, #last_row, #last_row_index, #new_format_column, #replace_row, #row_count, #update_row, #updated_from, #write, #write_column, #write_row, #write_url

Constructor Details

#initialize(opts = {}) ⇒ Worksheet

Returns a new instance of Worksheet.



15
16
17
18
19
20
21
22
# File 'lib/spreadsheet/excel/worksheet.rb', line 15

def initialize opts = {}
  @row_addresses = nil
  super
  @offset, @ole, @reader = opts[:offset], opts[:ole], opts[:reader]
  @dimensions = nil
  @links = {}
  @guts = {}
end

Instance Attribute Details

#gutsObject (readonly)

Returns the value of attribute guts.



14
15
16
# File 'lib/spreadsheet/excel/worksheet.rb', line 14

def guts
  @guts
end

Returns the value of attribute links.



14
15
16
# File 'lib/spreadsheet/excel/worksheet.rb', line 14

def links
  @links
end

#offsetObject (readonly)

Returns the value of attribute offset.



14
15
16
# File 'lib/spreadsheet/excel/worksheet.rb', line 14

def offset
  @offset
end

#oleObject (readonly)

Returns the value of attribute ole.



14
15
16
# File 'lib/spreadsheet/excel/worksheet.rb', line 14

def ole
  @ole
end

Instance Method Details



23
24
25
# File 'lib/spreadsheet/excel/worksheet.rb', line 23

def add_link row, column, link
  @links.store [row, column], link
end

#column(idx) ⇒ Object



26
27
28
29
# File 'lib/spreadsheet/excel/worksheet.rb', line 26

def column idx
  ensure_rows_read
  super
end

#date_baseObject



30
31
32
# File 'lib/spreadsheet/excel/worksheet.rb', line 30

def date_base
  @workbook.date_base
end

#each(*args) ⇒ Object



33
34
35
36
# File 'lib/spreadsheet/excel/worksheet.rb', line 33

def each *args
  ensure_rows_read
  super
end

#ensure_rows_readObject



37
38
39
40
41
42
# File 'lib/spreadsheet/excel/worksheet.rb', line 37

def ensure_rows_read
  return if @row_addresses
  @dimensions = nil
  @row_addresses = []
  @reader.read_worksheet self, @offset if @reader
end

#row(idx) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spreadsheet/excel/worksheet.rb', line 43

def row idx
  @rows[idx] or begin
    ensure_rows_read
    if addr = @row_addresses[idx]
      row = @reader.read_row self, addr
      [:default_format, :height, :outline_level, :hidden, ].each do |key|
        row.send "unupdated_#{key}=", addr[key]
      end
      row.worksheet = self
      row
    else
      Row.new self, idx
    end
  end
end

#row_updated(idx, row) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/spreadsheet/excel/worksheet.rb', line 58

def row_updated idx, row
  res = super
  @workbook.changes.store self, true
  @workbook.changes.store :boundsheets, true
  @changes.store idx, true
  @changes.store :dimensions, true
  res
end

#set_row_address(idx, opts) ⇒ Object



66
67
68
69
# File 'lib/spreadsheet/excel/worksheet.rb', line 66

def set_row_address idx, opts
  @offsets.store idx, opts[:row_block]
  @row_addresses[idx] = opts
end

#shared_string(idx) ⇒ Object



70
71
72
# File 'lib/spreadsheet/excel/worksheet.rb', line 70

def shared_string idx
  @workbook.shared_string idx
end