class Axlsx::RichTextRun

The RichTextRun class creates and self serializing text run.

def autowidth(widtharray)

Returns:
  • (Array) -

Parameters:
  • widtharray (Array) -- this array is populated with the widths of each line in the run.
def autowidth(widtharray)
  return if value.nil?
  if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
    first = true
    value.to_s.split(/\r?\n/, -1).each do |line|
      if first
        first = false
      else
        widtharray << 0
      end
      widtharray[-1] += string_width(line, font_size)
    end
  else
    widtharray[-1] += string_width(value.to_s, font_size)
  end
  widtharray
end

def b=(v) set_run_style :validate_boolean, :b, v; end

Other tags:
    See: b -
def b=(v) set_run_style :validate_boolean, :b, v; end

def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end

Other tags:
    See: charset -
def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end

def color=(v)

Parameters:
  • v (String) -- The 8 character representation for an rgb color #FFFFFFFF"
def color=(v)
  @color = v.is_a?(Color) ? v : Color.new(:rgb => v)
end

def condense=(v) set_run_style :validate_boolean, :condense, v; end

Other tags:
    See: condense -
def condense=(v) set_run_style :validate_boolean, :condense, v; end

def extend=(v) set_run_style :validate_boolean, :extend, v; end

Other tags:
    See: extend -
def extend=(v) set_run_style :validate_boolean, :extend, v; end

def family=(v)

Other tags:
    See: family -
def family=(v)
  set_run_style :validate_family, :family, v.to_i
end

def font_name=(v) set_run_style :validate_string, :font_name, v; end

Other tags:
    See: font_name -
def font_name=(v) set_run_style :validate_string, :font_name, v; end

def font_size

imagemagick and loading metrics for every character.
the cell itself. Yes, it is a bit of a hack, but it is much better than using
we scale the font size if bold style is applied to either the style font or
def font_size
  return sz if sz
  font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
  (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
end

def i=(v) set_run_style :validate_boolean, :i, v; end

Other tags:
    See: i -
def i=(v) set_run_style :validate_boolean, :i, v; end

def initialize(value, options = {})

def initialize(value, options = {})
  self.value = value
  parse_options(options)
end

def outline=(v) set_run_style :validate_boolean, :outline, v; end

Other tags:
    See: outline -
def outline=(v) set_run_style :validate_boolean, :outline, v; end

def scheme=(v)

Other tags:
    See: scheme -
def scheme=(v)
  RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
  set_run_style nil, :scheme, v
end

def set_run_style(validator, attr, value)

Utility method for setting inline style attributes
def set_run_style(validator, attr, value)
  return unless INLINE_STYLES.include?(attr.to_sym)
  Axlsx.send(validator, value) unless validator.nil?
  self.instance_variable_set :"@#{attr.to_s}", value
end

def shadow=(v) set_run_style :validate_boolean, :shadow, v; end

Other tags:
    See: shadow -
def shadow=(v) set_run_style :validate_boolean, :shadow, v; end

def strike=(v) set_run_style :validate_boolean, :strike, v; end

Other tags:
    See: strike -
def strike=(v) set_run_style :validate_boolean, :strike, v; end

def string_width(string, font_size)

- scaling is not linear as font sizes increase
This is still not perfect...
Returns the width of a string according to the current style
def string_width(string, font_size)
  font_scale = font_size / 10.0
  string.size * font_scale
end

def style

def style
  cell.style
end

def styles

def styles
  cell.row.worksheet.styles
end

def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end

Other tags:
    See: sz -
def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end

def to_xml_string(str = '')

Returns:
  • (String) -

Parameters:
  • str (String) --
def to_xml_string(str = '')
  valid = RichTextRun::INLINE_STYLES
  data = Hash[Axlsx.instance_values_for(self).map { |k, v| [k.to_sym, v] }]
  data = data.select { |key, value| valid.include?(key) && !value.nil? }
  str << '<r><rPr>'
  data.keys.each do |key|
    case key
    when :font_name
      str << ('<rFont val="' << font_name << '"/>')
    when :color
      str << data[key].to_xml_string
    else
      str << ('<' << key.to_s << ' val="' << xml_value(data[key]) << '"/>')
    end
  end
  clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
  str << ('</rPr><t>' << clean_value << '</t></r>')
end

def u=(v)

Other tags:
    See: u -
def u=(v)
  v = :single if (v == true || v == 1 || v == :true || v == 'true')
  set_run_style :validate_cell_u, :u, v
end

def value=(value)

def value=(value)
  @value = value
end

def vertAlign=(v)

Other tags:
    See: vertAlign -
def vertAlign=(v)
  RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
  set_run_style nil, :vertAlign, v
end

def xml_value value

Numbers)
Converts the value to the correct XML representation (fixes issues with
def xml_value value
  if value == true
    1
  elsif value == false
    0
  else
    value
  end.to_s
end