class Axlsx::RichTextRun
The RichTextRun class creates and self serializing text run.
def autowidth(widtharray)
-
(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
- 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
- See: charset -
def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
def color=(v)
-
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
- See: condense -
def condense=(v) set_run_style :validate_boolean, :condense, v; end
def extend=(v) set_run_style :validate_boolean, :extend, v; end
- See: extend -
def extend=(v) set_run_style :validate_boolean, :extend, v; end
def family=(v)
- 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
- See: font_name -
def font_name=(v) set_run_style :validate_string, :font_name, v; end
def font_size
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
- 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
- See: outline -
def outline=(v) set_run_style :validate_boolean, :outline, v; end
def scheme=(v)
- 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)
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
- See: shadow -
def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
def strike=(v) set_run_style :validate_boolean, :strike, v; end
- See: strike -
def strike=(v) set_run_style :validate_boolean, :strike, v; end
def string_width(string, font_size)
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
- See: sz -
def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
def to_xml_string(str = '')
-
(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)
- 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)
- See: vertAlign -
def vertAlign=(v) RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v set_run_style nil, :vertAlign, v end
def xml_value value
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