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.
342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/spreadshoot.rb', line 342 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>
338 339 340 |
# File 'lib/spreadshoot.rb', line 338 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>
338 339 340 |
# File 'lib/spreadshoot.rb', line 338 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>
338 339 340 |
# File 'lib/spreadshoot.rb', line 338 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>
338 339 340 |
# File 'lib/spreadshoot.rb', line 338 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>
338 339 340 |
# File 'lib/spreadshoot.rb', line 338 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>
338 339 340 |
# File 'lib/spreadshoot.rb', line 338 def xml @xml end |
Instance Method Details
#row(options = {}, &block) ⇒ Object
Creates a row within a worksheet.
389 390 391 392 393 |
# File 'lib/spreadshoot.rb', line 389 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.
414 415 416 |
# File 'lib/spreadshoot.rb', line 414 def set_col_width col, width @column_widths[col] = width end |
#table(options = {}) {|table| ... } ⇒ Table
Creates a table within a worksheet.
403 404 405 406 407 408 409 410 |
# File 'lib/spreadshoot.rb', line 403 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
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/spreadshoot.rb', line 358 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 |