Class: Axlsx::DefinedName

Inherits:
Object
  • Object
show all
Includes:
Accessors, OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/defined_name.rb

Overview

This element defines the defined names that are defined within this workbook. Defined names are descriptive text that is used to represents a cell, range of cells, formula, or constant value. Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30. A defined name in a formula can make it easier to understand the purpose of the formula. Names are available to any sheet. Names can also be used to represent formulas or values that do not change (constants).

You can also link to a defined name in another workbook, or define a name that refers to cells in another workbook.

A compliant producer or consumer considers a defined name in the range A1-XFD1048576 to be an error. All other names outside this range can be defined as names and overrides a cell reference if an ambiguity exists.

Examples:

The formula =SUM(FirstQuarterSales) might be easier to identify than =SUM(C20:C30
If the name ProjectedSales refers to the range A20:A30 on the first worksheet in a workbook,
you can use the name ProjectedSales on any other sheet in the same workbook to refer to range A20:A30 on the first worksheet.
The name SalesTax can be used to represent the sales tax amount (such as 6.2 percent) applied to sales transactions.
The formula =SUM(Sales.xls!ProjectedSales) refers to the named range ProjectedSales in the workbook named Sales.
For clarification: LOG10 is always a cell reference, LOG10() is always formula, LOGO1000 can be a defined name that overrides a cell reference.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Constructor Details

#initialize(formula, options = {}) ⇒ DefinedName

creates a new DefinedName.

Parameters:

  • formula (String)
    • the formula the defined name references
  • options (Hash) (defaults to: {})
    • A hash of key/value pairs that will be mapped to this instances attributes.
  • [String] (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

  • [Integer] (Hash)

    a customizable set of options



100
101
102
103
# File 'lib/axlsx/workbook/defined_name.rb', line 100

def initialize(formula, options={})
  @formula = formula
  parse_options options
end

Instance Attribute Details

#local_sheet_idObject

Returns the value of attribute local_sheet_id.



105
106
107
# File 'lib/axlsx/workbook/defined_name.rb', line 105

def local_sheet_id
  @local_sheet_id
end

Instance Method Details

#to_xml_string(str = '') ⇒ Object

Raises:

  • (ArgumentError)


121
122
123
124
125
126
# File 'lib/axlsx/workbook/defined_name.rb', line 121

def to_xml_string(str='')
  raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name
  str << ('<definedName ' << 'name="' << name << '" ')
  serialized_attributes str
  str << ('>' << @formula << '</definedName>')
end