Class: Spreadsheet::Excel::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/roo/excel.rb

Overview

patch for ruby-spreadsheet parsing formulas

Instance Method Summary collapse

Instance Method Details

#read_formula(worksheet, addr, work) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/roo/excel.rb', line 46

def read_formula worksheet, addr, work
  row, column, xf, rtype, rval, rcheck, opts = work.unpack 'v3CxCx3v2'
  formula = Formula.new
  formula.shared = (opts & 0x08) > 0
  formula.data = work[20..-1]
  if rcheck != 0xffff || rtype > 3 
    value, = work.unpack 'x6E'
    unless value
      # on architectures where sizeof(double) > 8
      value, = work.unpack 'x6e'
    end
    formula.value = value
  elsif rtype == 0
    pos, op, len, work = get_next_chunk
    if op == :string
      formula.value = client read_string(work, 2), @workbook.encoding
    else
      # This seems to work but I don't know why :). It at least
      # seems to correct the case we saw but doubtful it's the right fix
      formula.value = client read_string(work[10..-1], 2), @workbook.encoding
    end
  elsif rtype == 1
    formula.value = rval > 0
  elsif rtype == 2
    formula.value = Error.new rval
  else
    # leave the Formula value blank
  end
  set_cell worksheet, row, column, xf, formula
end