Class: Axlsx::Cell
- Inherits:
-
Object
- Object
- Axlsx::Cell
- Defined in:
- lib/axlsx/workbook/worksheet/cell.rb
Overview
The recommended way to generate cells is via Worksheet#add_row
A cell in a worksheet. Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell’s type will recast the value to the type specified. Altering the cell’s value via the property accessor will also automatically cast the provided value to the cell’s type.
Instance Attribute Summary collapse
-
#b ⇒ Boolean
The inline bold property for the cell.
-
#charset ⇒ String
The inline charset property for the cell.
-
#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 ⇒ String
The inline family property for the cell.
-
#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.
-
#row ⇒ Row
readonly
The row this cell belongs to.
-
#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.
-
#strike ⇒ Boolean
The inline strike property for the cell.
-
#style ⇒ Integer
The index of the cellXfs item to be applied to this cell.
-
#sz ⇒ Boolean
The inline sz property for the cell.
-
#type ⇒ Symbol
The cell’s data type.
-
#u ⇒ Boolean
The inline underline property for the cell.
-
#value ⇒ String, ...
The value of this cell.
-
#vertAlign ⇒ Symbol
The inline vertical alignment property for the cell this must be one of [:baseline, :subscript, :superscript].
Instance Method Summary collapse
-
#index ⇒ Integer
The index of the cell in the containing row.
-
#initialize(row, value = "", options = {}) ⇒ Cell
constructor
A new instance of Cell.
-
#pos ⇒ Array
Of x/y coordinates in the cheet for this cell.
-
#r ⇒ String
The alpha(column)numeric(row) reference for this sell.
-
#r_abs ⇒ String
The absolute alpha(column)numeric(row) reference for this sell.
-
#to_xml(xml) ⇒ String
Serializes the cell.
Constructor Details
#initialize(row, value = "", options = {}) ⇒ Cell
Returns a new instance of Cell.
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 177 def initialize(row, value="", ={}) self.row=row @styles = row.worksheet.workbook.styles @style = 0 @type = cell_type_from_value(value) @row.cells << self .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end @value = cast_value(value) end |
Instance Attribute Details
#b ⇒ Boolean
The inline bold property for the cell
84 85 86 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 84 def b @b end |
#charset ⇒ String
The inline charset property for the cell
72 73 74 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 72 def charset @charset end |
#color ⇒ Color
The inline color property for the cell
132 133 134 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 132 def color @color end |
#condense ⇒ Boolean
The inline condense property for the cell
114 115 116 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 114 def condense @condense end |
#extend ⇒ Boolean
The inline extend property for the cell
120 121 122 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 120 def extend @extend end |
#family ⇒ String
The inline family property for the cell
78 79 80 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 78 def family @family end |
#font_name ⇒ String
The inline font_name property for the cell
66 67 68 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 66 def font_name @font_name end |
#i ⇒ Boolean
The inline italic property for the cell
90 91 92 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 90 def i @i end |
#outline ⇒ Boolean
The inline outline property for the cell
102 103 104 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 102 def outline @outline end |
#row ⇒ Row
The row this cell belongs to.
33 34 35 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 33 def row @row end |
#scheme ⇒ Symbol
The inline scheme property for the cell this must be one of [:none, major, minor]
154 155 156 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 154 def scheme @scheme end |
#shadow ⇒ Boolean
The inline shadow property for the cell
108 109 110 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 108 def shadow @shadow end |
#strike ⇒ Boolean
The inline strike property for the cell
96 97 98 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 96 def strike @strike end |
#style ⇒ Integer
The index of the cellXfs item to be applied to this cell.
29 30 31 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 29 def style @style end |
#sz ⇒ Boolean
The inline sz property for the cell
140 141 142 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 140 def sz @sz end |
#type ⇒ Symbol
If the value provided cannot be cast into the type specified, type is changed to :string and the following logic is applied.
:string to :integer or :float, type coversions always return 0 or 0.0
:string, :integer, or :float to :time conversions always return the original value as a string and set the cells type to :string.
No support is currently implemented for parsing time strings.
The cell’s data type. Currently only four types are supported, :time, :float, :integer and :string. Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is automatically determed.
46 47 48 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 46 def type @type end |
#u ⇒ Boolean
The inline underline property for the cell
126 127 128 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 126 def u @u end |
#value ⇒ String, ...
The value of this cell.
57 58 59 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 57 def value @value end |
#vertAlign ⇒ Symbol
The inline vertical alignment property for the cell this must be one of [:baseline, :subscript, :superscript]
147 148 149 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 147 def vertAlign @vertAlign end |
Instance Method Details
#index ⇒ Integer
Returns The index of the cell in the containing row.
190 191 192 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 190 def index @row.cells.index(self) end |
#pos ⇒ Array
Returns of x/y coordinates in the cheet for this cell.
218 219 220 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 218 def pos [index, row.index] end |
#r ⇒ String
Returns The alpha(column)numeric(row) reference for this sell.
197 198 199 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 197 def r "#{col_ref}#{@row.index+1}" end |
#r_abs ⇒ String
Returns The absolute alpha(column)numeric(row) reference for this sell.
204 205 206 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 204 def r_abs "$#{r.split('').join('$')}" end |
#to_xml(xml) ⇒ String
Shared Strings are not used in this library. All values are set directly in the each sheet.
Serializes the cell
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 227 def to_xml(xml) # however nokogiri does a nice 'force_encoding' which we shall remove! if @type == :string #parse formula if @value.start_with?('=') xml.c(:r => r, :t=>:str, :s=>style) { xml.f @value.to_s.gsub('=', '') } else #parse standard string #xml.c(:r => r, :t=>:inlineStr, :s=>style) { # xml.is { xml.t @value.to_s } #} #parse styled string xml.c(:r => r, :s=>style, :t => :inlineStr) { xml.is { xml.r { xml.rPr { xml.rFont(:val=>@font_name) if @font_name xml.charset(:val=>@charset) if @charset xml.family(:val=>@family) if @family xml.b(:val=>@b) if @b xml.i(:val=>@i) if @i xml.strike(:val=>@strike) if @strike xml.outline(:val=>@outline) if @outline xml.shadow(:val=>@shadow) if @shadow xml.condense(:val=>@condense) if @condense xml.extend(:val=>@extend) if @extend @color.to_xml(xml) if @color xml.sz(:val=>@sz) if @sz xml.u(:val=>@u) if @u # :baseline, :subscript, :superscript xml.vertAlign(:val=>@vertAlign) if @verAlign # :none, major, :minor xml.scheme(:val=>@scheme) if @scheme } xml.t @value.to_s } } } end else xml.c(:r => r, :s => style) { xml.v value } end end |