Class: Writexlsx::Worksheet::FormulaCellData

Inherits:
CellData
  • Object
show all
Defined in:
lib/write_xlsx/worksheet.rb

Overview

:nodoc:

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary

Attributes inherited from CellData

#col, #link_type, #range, #result, #row, #tip, #token, #url, #xf

Instance Method Summary collapse

Methods inherited from CellData

#cell_attributes

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, delete_files, #ptrue?, #put_deprecate_message, #row_col_notation, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #write_color, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initialize(worksheet, row, col, formula, xf, result) ⇒ FormulaCellData

Returns a new instance of FormulaCellData.



213
214
215
216
# File 'lib/write_xlsx/worksheet.rb', line 213

def initialize(worksheet, row, col, formula, xf, result)
  @worksheet = worksheet
  @row, @col, @token, @xf, @result = row, col, formula, xf, result
end

Instance Method Details

#dataObject



218
219
220
# File 'lib/write_xlsx/worksheet.rb', line 218

def data
  @result || 0
end

#write_cellObject



222
223
224
225
226
227
228
229
230
231
# File 'lib/write_xlsx/worksheet.rb', line 222

def write_cell
  attributes = cell_attributes
  if @result &&  !(@result.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
    attributes << 't' << 'str'
  end
  @worksheet.writer.tag_elements('c', attributes) do
    @worksheet.write_cell_formula(token)
    @worksheet.write_cell_value(result || 0)
  end
end