Class: Axlsx::RichTextRun
- Inherits:
-
Object
- Object
- Axlsx::RichTextRun
- Includes:
- OptionsParser
- Defined in:
- lib/axlsx/workbook/worksheet/rich_text_run.rb
Constant Summary collapse
- INLINE_STYLES =
[:font_name, :charset, :family, :b, :i, :strike, :outline, :shadow, :condense, :extend, :u, :vertAlign, :sz, :color, :scheme].freeze
Instance Attribute Summary collapse
-
#b ⇒ Boolean
The inline bold property for the cell.
-
#cell ⇒ Object
Returns the value of attribute cell.
-
#charset ⇒ String
The inline charset property for the cell As far as I can tell, this is pretty much ignored.
-
#color ⇒ Color
The inline color property for the cell.
-
#condense ⇒ Boolean
The inline condense property for the cell.
-
#extend ⇒ Boolean
The inline extend property for the cell.
-
#family ⇒ Integer
The inline family property for the cell 1 Roman 2 Swiss 3 Modern 4 Script 5 Decorative.
-
#font_name ⇒ String
The inline font_name property for the cell.
-
#i ⇒ Boolean
The inline italic property for the cell.
-
#outline ⇒ Boolean
The inline outline property for the cell.
-
#scheme ⇒ Symbol
The inline scheme property for the cell this must be one of [:none, major, minor].
-
#shadow ⇒ Boolean
The inline shadow property for the cell.
-
#ssti ⇒ Integer
readonly
The Shared Strings Table index for this cell.
-
#strike ⇒ Boolean
The inline strike property for the cell.
-
#sz ⇒ Inteter
The inline sz property for the cell.
-
#u ⇒ Boolean, String
The inline underline property for the cell.
-
#value ⇒ Object
Returns the value of attribute value.
-
#vertAlign ⇒ Symbol
The inline vertical alignment property for the cell this must be one of [:baseline, :subscript, :superscript].
Instance Method Summary collapse
- #autowidth(widtharray) ⇒ Object
-
#initialize(value, options = {}) ⇒ RichTextRun
constructor
A new instance of RichTextRun.
-
#set_run_style(validator, attr, value) ⇒ Object
Utility method for setting inline style attributes.
-
#style=(v) ⇒ Integer
The cellXfs item index applied to this cell.
- #to_xml_string(str = '') ⇒ Object
Methods included from OptionsParser
Constructor Details
#initialize(value, options = {}) ⇒ RichTextRun
Returns a new instance of RichTextRun.
13 14 15 16 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 13 def initialize(value, ={}) self.value = value () end |
Instance Attribute Details
#b ⇒ Boolean
The inline bold property for the cell
71 72 73 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 71 def b @b end |
#cell ⇒ Object
Returns the value of attribute cell.
22 23 24 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 22 def cell @cell end |
#charset ⇒ String
The inline charset property for the cell As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following: 0  ANSI_CHARSET 1 DEFAULT_CHARSET 2 SYMBOL_CHARSET 77 MAC_CHARSET 128 SHIFTJIS_CHARSET 129  HANGUL_CHARSET 130  JOHAB_CHARSET 134  GB2312_CHARSET 136  CHINESEBIG5_CHARSET 161  GREEK_CHARSET 162  TURKISH_CHARSET 163  VIETNAMESE_CHARSET 177  HEBREW_CHARSET 178  ARABIC_CHARSET 186  BALTIC_CHARSET 204  RUSSIAN_CHARSET 222  THAI_CHARSET 238  EASTEUROPE_CHARSET 255  OEM_CHARSET
52 53 54 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 52 def charset @charset end |
#color ⇒ Color
The inline color property for the cell
125 126 127 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 125 def color @color end |
#condense ⇒ Boolean
The inline condense property for the cell
101 102 103 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 101 def condense @condense end |
#extend ⇒ Boolean
The inline extend property for the cell
107 108 109 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 107 def extend @extend end |
#family ⇒ Integer
The inline family property for the cell 1 Roman 2 Swiss 3 Modern 4 Script 5 Decorative
63 64 65 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 63 def family @family end |
#font_name ⇒ String
The inline font_name property for the cell
26 27 28 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 26 def font_name @font_name end |
#i ⇒ Boolean
The inline italic property for the cell
77 78 79 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 77 def i @i end |
#outline ⇒ Boolean
The inline outline property for the cell
89 90 91 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 89 def outline @outline end |
#scheme ⇒ Symbol
The inline scheme property for the cell this must be one of [:none, major, minor]
150 151 152 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 150 def scheme @scheme end |
#shadow ⇒ Boolean
The inline shadow property for the cell
95 96 97 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 95 def shadow @shadow end |
#ssti ⇒ Integer (readonly)
The Shared Strings Table index for this cell
159 160 161 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 159 def ssti @ssti end |
#strike ⇒ Boolean
The inline strike property for the cell
83 84 85 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 83 def strike @strike end |
#sz ⇒ Inteter
The inline sz property for the cell
133 134 135 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 133 def sz @sz end |
#u ⇒ Boolean, String
true is for backwards compatability and is reassigned to :single
The inline underline property for the cell. It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
116 117 118 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 116 def u @u end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 6 def value @value end |
#vertAlign ⇒ Symbol
The inline vertical alignment property for the cell this must be one of [:baseline, :subscript, :superscript]
140 141 142 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 140 def vertAlign @vertAlign end |
Instance Method Details
#autowidth(widtharray) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 170 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 |
#set_run_style(validator, attr, value) ⇒ Object
Utility method for setting inline style attributes
189 190 191 192 193 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 189 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 |
#style=(v) ⇒ Integer
Returns The cellXfs item index applied to this cell.
163 164 165 166 167 168 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 163 def style=(v) Axlsx::validate_unsigned_int(v) count = styles.cellXfs.size raise ArgumentError, "Invalid cellXfs id" unless v < count @style = v end |
#to_xml_string(str = '') ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 195 def to_xml_string(str = '') valid = RichTextRun::INLINE_STYLES data = Hash[self.instance_values.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 |