Method: Axlsx::Styles#parse_num_fmt_options

Defined in:
lib/axlsx/stylesheet/styles.rb

#parse_num_fmt_options(options = {}) ⇒ NumFmt|Integer

Parses Style#add_style options for number formatting. noop if neither :format_code or :num_format options are set.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • A (Hash)

    hash describing the :format_code and/or :num_fmt integer for the style.

Returns:



468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/axlsx/stylesheet/styles.rb', line 468

def parse_num_fmt_options(options = {})
  return if (options.keys & [:format_code, :num_fmt]).empty?

  # When the user provides format_code - we always need to create a new numFmt object
  # When the type is :dxf we always need to create a new numFmt object
  if options[:format_code] || options[:type] == :dxf
    # If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
    options[:num_fmt] ||= (@numFmts.map { |num_fmt| num_fmt.numFmtId }.max + 1) if options[:type] != :dxf
    numFmt = NumFmt.new(:numFmtId => options[:num_fmt] || 0, :formatCode => options[:format_code].to_s)
    options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
  else
    options[:num_fmt]
  end
end