Class: RubyXL::Worksheet

Inherits:
OOXMLObject show all
Includes:
LegacyWorksheet
Defined in:
lib/rubyXL/objects/worksheet.rb

Overview

Instance Attribute Summary

Attributes included from LegacyWorksheet

#extLst, #sheet_id, #sheet_name, #validations, #workbook

Instance Method Summary collapse

Methods included from LegacyWorksheet

#[], #add_cell, #add_row, #change_column_bold, #change_column_border_bottom, #change_column_border_diagonal, #change_column_border_left, #change_column_border_right, #change_column_border_top, #change_column_fill, #change_column_font_color, #change_column_font_name, #change_column_font_size, #change_column_horizontal_alignment, #change_column_italics, #change_column_strikethrough, #change_column_underline, #change_column_vertical_alignment, #change_column_width, #change_row_bold, #change_row_border_bottom, #change_row_border_diagonal, #change_row_border_left, #change_row_border_right, #change_row_border_top, #change_row_fill, #change_row_font_color, #change_row_font_name, #change_row_font_size, #change_row_height, #change_row_horizontal_alignment, #change_row_italics, #change_row_strikethrough, #change_row_underline, #change_row_vertical_alignment, #delete_cell, #delete_column, #delete_row, #each, #extract_data, #get_column_border_bottom, #get_column_border_diagonal, #get_column_border_left, #get_column_border_right, #get_column_border_top, #get_column_fill, #get_column_font_color, #get_column_font_name, #get_column_font_size, #get_column_horizontal_alignment, #get_column_vertical_alignment, #get_column_width, #get_row_border_bottom, #get_row_border_diagonal, #get_row_border_left, #get_row_border_right, #get_row_border_top, #get_row_fill, #get_row_font_color, #get_row_font_name, #get_row_font_size, #get_row_height, #get_row_horizontal_alignment, #get_row_vertical_alignment, #get_table, #initialize, #insert_cell, #insert_column, #insert_row, #is_column_bolded, #is_column_italicized, #is_column_struckthrough, #is_column_underlined, #is_row_bolded, #is_row_italicized, #is_row_struckthrough, #is_row_underlined, #merge_cells

Methods inherited from OOXMLObject

#add_to_zip, define_attribute, define_child_node, define_element_name, #dup, filepath, #index_in_collection, #initialize, obtain_class_variable, parse, parse_file, set_countable, set_namespaces, #write_xml

Instance Method Details

#before_write_xmlObject

This method may need to be moved higher in the hierarchy



432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/rubyXL/objects/worksheet.rb', line 432

def before_write_xml # This method may need to be moved higher in the hierarchy
  first_nonempty_row = nil
  last_nonempty_row = 0
  first_nonempty_column = nil
  last_nonempty_column = 0

  if sheet_data then
    sheet_data.rows.each_with_index { |row, row_index|
      next if row.nil? || row.cells.empty?

      first_nonempty_cell = nil
      last_nonempty_cell = 0

      row.cells.each_with_index { |cell, col_index|
        next if cell.nil?
        cell.r = RubyXL::Reference.new(row_index, col_index)

        first_nonempty_cell ||= col_index
        last_nonempty_cell = col_index
      }

      if first_nonempty_cell then # If there's nothing in this row, then +first_nonempty_cell+ will be +nil+.
        last_nonempty_row = row_index
        first_nonempty_row ||= row_index

        first_nonempty_column ||= first_nonempty_cell
        last_nonempty_column = last_nonempty_cell if last_nonempty_cell > last_nonempty_column
      end

      row.r = row_index + 1
      row.spans = "#{first_nonempty_cell + 1}:#{last_nonempty_cell + 1}"
      row.custom_format = (row.s.to_i != 0)
    }

    if first_nonempty_row then
      self.dimension ||= RubyXL::WorksheetDimensions.new
      self.dimension.ref = RubyXL::Reference.new(first_nonempty_row, last_nonempty_row,
                                                 first_nonempty_column, last_nonempty_column)
    end

  end

  true
end

#merged_cellsObject



477
478
479
# File 'lib/rubyXL/objects/worksheet.rb', line 477

def merged_cells
  (merged_cells_list && merged_cells_list.merge_cell) || []
end