Module: RubyXL::LegacyWorksheet

Includes:
Enumerable
Included in:
Worksheet
Defined in:
lib/rubyXL/legacy_worksheet.rb

Constant Summary collapse

TEXT_LENGTH_LIMIT_IN_CELL =

2 ** 15 - 1

32767

Instance Method Summary collapse

Instance Method Details

#add_cell(row_index = 0, column_index = 0, data = '', formula = nil, overwrite = true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubyXL/legacy_worksheet.rb', line 19

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 data.length > TEXT_LENGTH_LIMIT_IN_CELL
          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 data.to_s.length > TEXT_LENGTH_LIMIT_IN_CELL
          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 TrueClass, FalseClass then
        c.raw_value = data ? 1 : 0
        c.datatype = RubyXL::DataType::BOOLEAN
      when NilClass then nil
      end
    end

    range = cols&.locate_range(column_index)
    c.style_index = row.style_index || range&.style_index || 0
    row.cells[column_index] = c
  end

  c
end

#initialize(params = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rubyXL/legacy_worksheet.rb', line 7

def initialize(params = {})
  super
  self.workbook   = params[:workbook]
  self.sheet_name = params[:sheet_name]
  self.sheet_id   = params[:sheet_id]
  self.sheet_data = RubyXL::SheetData.new
  self.cols = RubyXL::ColumnRanges.new
  @comments = [] # Do not optimize! These are arrays, so they will share the pointer!
  @printer_settings = []
  @generic_storage = []
end