module RubyXL::LegacyWorksheet

def add_cell(row_index = 0, column_index = 0, data = '', formula = nil, overwrite = true)

def add_cell(row_index = 0, column_index = 0, data = '', formula = nil, overwrite = true)
  validate_workbook
  validate_nonnegative(row_index)
  validate_nonnegative(column_index)
  row = sheet_data.rows[row_index] || add_row(row_index)
  c = row.cells[column_index]
  if overwrite || c.nil?
    c = RubyXL::Cell.new
    c.worksheet = self
    c.row = row_index
    c.column = column_index
    if formula then
      c.formula = RubyXL::Formula.new(:expression => formula)
      c.raw_value = data
    else
      case data
      when Numeric          then c.raw_value = data
      when String           then
        if TEXT_LENGTH_LIMIT_IN_CELL < data.length
          raise ArgumentError, "The maximum length of cell contents (text) is #{TEXT_LENGTH_LIMIT_IN_CELL} characters"
        end
        c.raw_value = data
        c.datatype = RubyXL::DataType::RAW_STRING
      when RubyXL::RichText then
        if TEXT_LENGTH_LIMIT_IN_CELL < data.to_s.length
          raise ArgumentError, "The maximum length of cell contents (text) is #{TEXT_LENGTH_LIMIT_IN_CELL} characters"
        end
        c.is = data
        c.datatype = RubyXL::DataType::INLINE_STRING
      when Time, Date, DateTime then
        c.raw_value = workbook.date_to_num(data)
      when NilClass then nil
      end
    end
    range = cols && cols.locate_range(column_index)
    c.style_index = row.style_index || (range && range.style_index) || 0
    row.cells[column_index] = c
  end
  c
end