class RubyXL::Worksheet

www.datypic.com/sc/ooxml/e-ssml_worksheet.html

Constants

CONTENT_TYPE
REL_TYPE

Attributes

rels[RW]
sheet_id[RW]
sheet_name[RW]
state[RW]
workbook[RW]

Public Class Methods

parse(param) click to toggle source
Calls superclass method
# File lib/rubyXL/objects/worksheet.rb, line 736
def self.parse(param)
  sheet_obj = super
  sheet_obj.sheet_data.rows.each { |r|
    next if r.nil?
    r.worksheet = sheet_obj
    r.cells.each { |c| c.worksheet = sheet_obj unless c.nil? }
  }
  sheet_obj
end

Public Instance Methods

before_write_xml() click to toggle source
# File lib/rubyXL/objects/worksheet.rb, line 687
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}" unless first_nonempty_cell.nil?
      row.custom_format = (row.style_index.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
cell_at(ref) click to toggle source
# File lib/rubyXL/objects/worksheet.rb, line 754
def cell_at(ref)
  reference = RubyXL::Reference.new(ref)
  raise "Invalid reference: #{ref}" unless reference.valid? && reference.single_cell?
  sheet_data&.rows&.[](reference.first_row)&.cells&.[](reference.first_col)
end
get_col_xf(column_index) click to toggle source
# File lib/rubyXL/objects/worksheet.rb, line 746
def get_col_xf(column_index)
  workbook.stylesheet.cell_xfs[get_col_style(column_index)]
end
get_row_xf(row) click to toggle source
# File lib/rubyXL/objects/worksheet.rb, line 750
def get_row_xf(row)
  workbook.stylesheet.cell_xfs[get_row_style(row)]
end
xlsx_path() click to toggle source
# File lib/rubyXL/objects/worksheet.rb, line 732
def xlsx_path
  ROOT.join('xl', 'worksheets', "sheet#{file_index}.xml")
end