Class: Axlsx::NumFmt

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/stylesheet/num_fmt.rb

Overview

Note:

The recommended way to manage styles is Styles#add_style

A NumFmt object defines an identifier and formatting code for data in cells.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_element_attributes, #serialized_tag

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(options = {}) ⇒ NumFmt

Creates a new NumFmt object

Parameters:

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

    Options for the number format object

  • [Integer] (Hash)

    a customizable set of options

  • [String] (Hash)

    a customizable set of options



14
15
16
17
18
# File 'lib/axlsx/stylesheet/num_fmt.rb', line 14

def initialize(options={})
  @numFmtId = 0
  @formatCode = ""
  parse_options options
end

Instance Attribute Details

#formatCodeString

Returns The formatting to use for this number format.

Returns:

  • (String)

    The formatting to use for this number format.

See Also:



24
25
26
# File 'lib/axlsx/stylesheet/num_fmt.rb', line 24

def formatCode
  @formatCode
end

#numFmtIdInteger

Note:

These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS. 1 0 2 0.00 3 #,##0 4 #,##0.00 5 $#,##0_);($#,##0) 6 $#,##0_);Red 7 $#,##0.00_);($#,##0.00) 8 $#,##0.00_);Red 9 0% 10 0.00% 11 0.00E+00 12 # ?/? 13 # ??/?? 14 m/d/yyyy 15 d-mmm-yy 16 d-mmm 17 mmm-yy 18 h:mm AM/PM 19 h:mm:ss AM/PM 20 h:mm 21 h:mm:ss 22 m/d/yyyy h:mm 37 #,##0_);(#,##0) 38 #,##0_);Red 39 #,##0.00_);(#,##0.00) 40 #,##0.00_);Red 45 mm:ss 46 [h]:mm:ss 47 mm:ss.0 48 ##0.0E+0 49 @

Returns An unsigned integer referencing a standard or custom number format.

Returns:

  • (Integer)

    An unsigned integer referencing a standard or custom number format.

See Also:



61
62
63
# File 'lib/axlsx/stylesheet/num_fmt.rb', line 61

def numFmtId
  @numFmtId
end

Instance Method Details

#serialized_attributes(str = '', additional_attributes = {}) ⇒ Object

Override to avoid removing underscores



77
78
79
80
81
82
83
# File 'lib/axlsx/stylesheet/num_fmt.rb', line 77

def serialized_attributes(str = '', additional_attributes = {})
  attributes = declared_attributes.merge! additional_attributes
  attributes.each do |key, value|
    str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.booleanize(value)}\" "
  end
  str
end

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


72
73
74
# File 'lib/axlsx/stylesheet/num_fmt.rb', line 72

def to_xml_string(str = '')
  serialized_tag('numFmt', str)
end