Class: Spreadshoot::Worksheet
- Inherits:
-
Object
- Object
- Spreadshoot::Worksheet
- Defined in:
- lib/spreadshoot.rb
Overview
Single worksheet containing one or more tables.
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>.
-
#col_index ⇒ Object
readonly
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>.
-
#row_index ⇒ Object
readonly
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>.
-
#spreadsheet ⇒ Object
readonly
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>.
-
#title ⇒ Object
readonly
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>.
-
#xml ⇒ Object
readonly
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>.
Instance Method Summary collapse
-
#initialize(spreadsheet, title, options = {}) {|_self| ... } ⇒ Worksheet
constructor
Not intended to be called directly.
-
#row(options = {}, &block) ⇒ Object
Creates a row within a worksheet.
-
#set_col_width(col, width) ⇒ Object
Not intended to be used directly.
-
#table(options = {}) {|table| ... } ⇒ Table
Creates a table within a worksheet.
-
#to_s ⇒ Object
Outputs the worksheet as OOXML.
Constructor Details
#initialize(spreadsheet, title, options = {}) {|_self| ... } ⇒ Worksheet
Not intended to be called directly. Use Spreadshoot#worksheet to create a worksheet.
352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/spreadshoot.rb', line 352 def initialize spreadsheet, title, = {} @cells = {} @spreadsheet = spreadsheet @title = title @options = @row_index = 0 @col_index = 0 @column_widths = {} # default table, if none defined @current_table = Table.new(self, ) yield self end |
Instance Attribute Details
#cells ⇒ Object (readonly)
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>
348 349 350 |
# File 'lib/spreadshoot.rb', line 348 def cells @cells end |
#col_index ⇒ Object (readonly)
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>
348 349 350 |
# File 'lib/spreadshoot.rb', line 348 def col_index @col_index end |
#row_index ⇒ Object (readonly)
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>
348 349 350 |
# File 'lib/spreadshoot.rb', line 348 def row_index @row_index end |
#spreadsheet ⇒ Object (readonly)
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>
348 349 350 |
# File 'lib/spreadshoot.rb', line 348 def spreadsheet @spreadsheet end |
#title ⇒ Object (readonly)
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>
348 349 350 |
# File 'lib/spreadshoot.rb', line 348 def title @title end |
#xml ⇒ Object (readonly)
<worksheet xmlns=“schemas.openxmlformats.org/spreadsheetml/2006/main” > <sheetData> <row> <c> <v>1234</v> </c> </row> </sheetData> </worksheet>
348 349 350 |
# File 'lib/spreadshoot.rb', line 348 def xml @xml end |
Instance Method Details
#row(options = {}, &block) ⇒ Object
Creates a row within a worksheet.
399 400 401 402 403 |
# File 'lib/spreadshoot.rb', line 399 def row = {}, &block row = @current_table.row , &block @row_index += 1 row end |
#set_col_width(col, width) ⇒ Object
Not intended to be used directly.
424 425 426 |
# File 'lib/spreadshoot.rb', line 424 def set_col_width col, width @column_widths[col] = width end |
#table(options = {}) {|table| ... } ⇒ Table
Creates a table within a worksheet.
413 414 415 416 417 418 419 420 |
# File 'lib/spreadshoot.rb', line 413 def table = {} @current_table = table = Table.new(self, ) yield table @row_index = [@row_index, table.row_topleft + table.row_max].max @col_index = 0 @current_table = Table.new(self, @options) # preparing one in case row directly called next table end |
#to_s ⇒ Object
Outputs the worksheet as OOXML
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/spreadshoot.rb', line 368 def to_s @xml ||= Builder::XmlMarkup.new.worksheet(:xmlns => "http://schemas.openxmlformats.org/spreadsheetml/2006/main") do |ws| unless @column_widths.empty? ws.cols do |xcols| @column_widths.keys.sort.each do |i| width = @column_widths[i] params = {:min => i+1, :max => i+1, :bestFit => 1} params.merge!({:customWidth => 1, :width => width}) if width xcols.col(params) end end end ws.sheetData do |sd| @cells.keys.sort.each do |row| sd.row(:r => row+1) do |xr| @cells[row].keys.sort.each do |col| cell = @cells[row][col] cell.output(xr) end end end end end end |