Class: Writexlsx::Worksheet::FormulaCellData

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

Overview

:nodoc:

Constant Summary

Constants included from Utility

Utility::CHAR_WIDTHS, Utility::COL_MAX, Utility::PERL_TRUE_VALUES, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary collapse

Attributes inherited from CellData

#xf

Instance Method Summary collapse

Methods inherited from CellData

#cell_attributes, #display_url_string?

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #color, #convert_date_time, #convert_font_args, #dash_types, delete_files, #escape_url, #fill_properties, #float_to_str, #get_font_latin_attributes, #get_font_style_attributes, #get_image_properties, #layout_properties, #legend_properties, #line_fill_properties, #line_properties, #palette_color, #params_to_font, #pattern_properties, #pixels_to_points, #process_bmp, #process_gif, #process_jpg, #process_png, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_a_body_pr, #write_a_def_rpr, #write_a_end_para_rpr, #write_a_lst_style, #write_a_p_formula, #write_a_p_pr_formula, #write_a_solid_fill, #write_a_srgb_clr, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_def_rpr_r_pr_common, #write_div, #write_fill, #write_font, #write_stroke, #write_tx_pr, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xl_string_pixel_width, #xml_str

Constructor Details

#initialize(formula, xf, result) ⇒ FormulaCellData

Returns a new instance of FormulaCellData.



94
95
96
97
98
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 94

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

Instance Attribute Details

Returns the value of attribute link_type.



92
93
94
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 92

def link_type
  @link_type
end

#rangeObject (readonly)

Returns the value of attribute range.



92
93
94
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 92

def range
  @range
end

#resultObject (readonly)

Returns the value of attribute result.



92
93
94
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 92

def result
  @result
end

#tokenObject (readonly)

Returns the value of attribute token.



92
93
94
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 92

def token
  @token
end

#urlObject (readonly)

Returns the value of attribute url.



92
93
94
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 92

def url
  @url
end

Instance Method Details

#dataObject



100
101
102
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 100

def data
  @result || 0
end

#write_cell(worksheet, row, row_name, col) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/write_xlsx/worksheet/cell_data.rb', line 104

def write_cell(worksheet, row, row_name, col)
  truefalse = { 'TRUE' => 1, 'FALSE' => 0 }
  error_code = ['#DIV/0!', '#N/A', '#NAME?', '#NULL!', '#NUM!', '#REF!', '#VALUE!']

  attributes = cell_attributes(worksheet, row, row_name, col)
  if @result && !(@result.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
    if truefalse[@result]
      attributes << %w[t b]
      @result = truefalse[@result]
    elsif error_code.include?(@result)
      attributes << %w[t e]
    else
      attributes << %w[t str]
    end
  end
  worksheet.writer.tag_elements('c', attributes) do
    worksheet.write_cell_formula(token)
    worksheet.write_cell_value(result || 0)
  end
end