class Axlsx::Cell

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.

Returns a new instance of Cell


  • row (Row)

    The row this cell belongs to.

  • value (Any) (defaults to: nil)

    The value associated with this cell.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • type (Symbol)

    The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided.

  • style (Integer)

    The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied.

  • font_name (String)
  • charset (Integer)
  • family (String)
  • b (Boolean)
  • i (Boolean)
  • strike (Boolean)
  • outline (Boolean)
  • shadow (Boolean)
  • condense (Boolean)
  • extend (Boolean)
  • u (Boolean)
  • vertAlign (Symbol)

    must be one of :baseline, :subscript, :superscript

  • sz (Integer)
  • color (String)

    an 8 letter rgb specification

  • formula_value (Number)

    The value to cache for a formula cell.

  • scheme (Symbol)

    must be one of :none, major, :minor

The inline bold property for the cell


About Time - Time in OOXML is different from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.

Cast the value into this cells data type.


This is only used when a cell is created but no :type option is specified, the following rules apply:

  1. If the value is an instance of Date, the type is set to :date

  2. If the value is an instance of Time, the type is set to :time

  3. If the value is an instance of TrueClass or FalseClass, the type is set to :boolean

  4. :float and :integer types are determined by regular expression matching.

  5. Anything that does not meet either of the above is determined to be :string.

Determines the cell type based on the cell value.

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

Returns the sanatized value TODO find a better way to do this as it accounts for 30% of processing time in benchmarking…

The inline color property for the cell

The inline condense property for the cell

The inline extend property for the cell

The inline family property for the cell 1 Roman 2 Swiss 3 Modern 4 Script 5 Decorative

The inline font_name property for the cell

we scale the font size if bold style is applied to either the style font or the cell itself. Yes, it is a bit of a hack, but it is much better than using imagemagick and loading metrics for every character.

this is the cached value for formula cells. If you want the values to render in iOS/Mac OSX preview you need to set this.

The inline italic property for the cell

Returns The index of the cell in the containing row.

Indicates that the cell has one or more of the custom cell styles applied.

Merges all the cells in a range created between this cell and the cell or string name for a cell provided


  • target (Cell, String)

    The last cell, or str ref for the cell in the merge range

returns the name of the cell

The inline outline property for the cell

Indicates if the cell is good for shared string table

Returns of x/y coordinates in the sheet for this cell.

Returns The alpha(column)numeric(row) reference for this sell.


Relative Cell Reference

ws.rows.first.cells.first.r #=> "A1"

Returns The absolute alpha(column)numeric(row) reference for this sell.


Absolute Cell Reference

ws.rows.first.cells.first.r #=> "$A$1"

returns the absolute or relative string style reference for this cell. returned.


  • absolute (Boolean) (defaults to: true)

    -when false a relative reference will be

The row this cell belongs to.

The inline scheme property for the cell this must be one of [:none, major, minor]

Utility method for setting inline style attributes

The inline shadow property for the cell

The Shared Strings Table index for this cell

The inline strike property for the cell

Returns the width of a string according to the current style This is still not perfect…

- scaling is not linear as font sizes increase

The index of the cellXfs item to be applied to this cell.

Returns The cellXfs item index applied to this cell.


  • (ArgumentError)

    Invalid cellXfs id if the value provided is not within cellXfs items range.

The inline sz property for the cell

Serializes the cell


  • r_index (Integer)

    The row index for the cell

  • c_index (Integer)

    The cell index in the row.

  • str (String) (defaults to: '')

    The string index the cell content will be appended to. Defaults to empty string.


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 conversions 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 six types are supported, :date, :time, :float, :integer, :string and :boolean. 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.


  • (ArgumentExeption)

    Cell.type must be one of [:date, time, :float, :integer, :string, :boolean]


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

The value of this cell.

The inline vertical alignment property for the cell this must be one of [:baseline, :subscript, :superscript]

Cell is referenced in 0 repositories