Class: Roo::Excelx::Sheet
- Inherits:
-
Object
- Object
- Roo::Excelx::Sheet
- Defined in:
- lib/roo/excelx.rb
Instance Method Summary collapse
- #cells ⇒ Object
- #column(col_number) ⇒ Object
- #comments ⇒ Object
- #dimensions ⇒ Object
-
#each_row(options = {}, &block) ⇒ Object
Yield each row as array of Excelx::Cell objects accepts options max_rows (int) (offset by 1 for header) and pad_cells (boolean).
- #excelx_format(key) ⇒ Object
-
#first_column(sheet = nil) ⇒ Object
returns the number of the first non-empty column.
-
#first_row ⇒ Object
returns the number of the first non-empty row.
- #hyperlinks ⇒ Object
-
#initialize(name, rels_path, sheet_path, comments_path, styles, shared_strings, workbook) ⇒ Sheet
constructor
A new instance of Sheet.
-
#last_column(sheet = nil) ⇒ Object
returns the number of the last non-empty column.
- #last_row ⇒ Object
- #present_cells ⇒ Object
- #row(row_number) ⇒ Object
Constructor Details
#initialize(name, rels_path, sheet_path, comments_path, styles, shared_strings, workbook) ⇒ Sheet
Returns a new instance of Sheet.
148 149 150 151 152 153 154 |
# File 'lib/roo/excelx.rb', line 148 def initialize(name, rels_path, sheet_path, comments_path, styles, shared_strings, workbook) @name = name @rels = Relationships.new(rels_path) @comments = Comments.new(comments_path) @styles = styles @sheet = SheetDoc.new(sheet_path, @rels, @styles, shared_strings, workbook) end |
Instance Method Details
#cells ⇒ Object
156 157 158 |
# File 'lib/roo/excelx.rb', line 156 def cells @cells ||= @sheet.cells(@rels) end |
#column(col_number) ⇒ Object
182 183 184 185 186 |
# File 'lib/roo/excelx.rb', line 182 def column(col_number) first_row.upto(last_row).map do |row| cells[[row,col_number]] end.map {|cell| cell && cell.value } end |
#comments ⇒ Object
215 216 217 |
# File 'lib/roo/excelx.rb', line 215 def comments @comments.comments end |
#dimensions ⇒ Object
219 220 221 |
# File 'lib/roo/excelx.rb', line 219 def dimensions @sheet.dimensions end |
#each_row(options = {}, &block) ⇒ Object
Yield each row as array of Excelx::Cell objects accepts options max_rows (int) (offset by 1 for header) and pad_cells (boolean)
167 168 169 170 171 172 173 174 |
# File 'lib/roo/excelx.rb', line 167 def each_row( = {}, &block) row_count = 0 @sheet.each_row_streaming do |row| break if [:max_rows] && row_count == [:max_rows] + 1 block.call(cells_for_row_element(row, )) if block_given? row_count += 1 end end |
#excelx_format(key) ⇒ Object
207 208 209 |
# File 'lib/roo/excelx.rb', line 207 def excelx_format(key) @styles.style_format(cells[key].style).to_s end |
#first_column(sheet = nil) ⇒ Object
returns the number of the first non-empty column
198 199 200 |
# File 'lib/roo/excelx.rb', line 198 def first_column(sheet=nil) @first_column ||= present_cells.keys.map {|row, col| col }.min end |
#first_row ⇒ Object
returns the number of the first non-empty row
189 190 191 |
# File 'lib/roo/excelx.rb', line 189 def first_row @first_row ||= present_cells.keys.map {|row, col| row }.min end |
#hyperlinks ⇒ Object
211 212 213 |
# File 'lib/roo/excelx.rb', line 211 def hyperlinks @hyperlinks ||= @sheet.hyperlinks(@rels) end |
#last_column(sheet = nil) ⇒ Object
returns the number of the last non-empty column
203 204 205 |
# File 'lib/roo/excelx.rb', line 203 def last_column(sheet=nil) @last_column ||= present_cells.keys.map {|row, col| col }.max end |
#last_row ⇒ Object
193 194 195 |
# File 'lib/roo/excelx.rb', line 193 def last_row @last_row ||= present_cells.keys.map {|row, col| row }.max end |
#present_cells ⇒ Object
160 161 162 |
# File 'lib/roo/excelx.rb', line 160 def present_cells @present_cells ||= cells.select {|key, cell| cell && cell.value } end |
#row(row_number) ⇒ Object
176 177 178 179 180 |
# File 'lib/roo/excelx.rb', line 176 def row(row_number) first_column.upto(last_column).map do |col| cells[[row_number,col]] end.map {|cell| cell && cell.value } end |