Class: Axlsx::PivotTableCacheDefinition

Inherits:
Object
  • Object
show all
Includes:
OptionsParser
Defined in:
lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb

Overview

Note:

Worksheet#add_pivot_table is the recommended way to create tables for your worksheets.

Table

See Also:

  • for examples

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(pivot_table) ⇒ PivotTableCacheDefinition

Creates a new PivotTable object

Parameters:

  • pivot_table (String)

    The pivot table this cache definition is in



12
13
14
# File 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb', line 12

def initialize(pivot_table)
  @pivot_table = pivot_table
end

Instance Attribute Details

#pivot_tableObject (readonly)

The reference to the pivot table data

@return [PivotTable]



18
19
20
# File 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb', line 18

def pivot_table
  @pivot_table
end

Instance Method Details

#cache_idInteger

The identifier for this cache

Returns:

  • (Integer)


34
35
36
# File 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb', line 34

def cache_id
  index + 1
end

#indexInteger

The index of this chart in the workbooks charts collection

Returns:

  • (Integer)


22
23
24
# File 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb', line 22

def index
  pivot_table.sheet.workbook.pivot_tables.index(pivot_table)
end

#pnString

The part name for this table

Returns:

  • (String)


28
29
30
# File 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb', line 28

def pn
  "#{PIVOT_TABLE_CACHE_DEFINITION_PN % (index+1)}"
end

#rIdString

The relationship id for this pivot table cache definition.

Returns:

  • (String)

See Also:



41
42
43
# File 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb', line 41

def rId
  pivot_table.relationships.for(self).Id
end

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb', line 48

def to_xml_string(str = '')
  str << '<?xml version="1.0" encoding="UTF-8"?>'
  str << ('<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">')
  str <<   '<cacheSource type="worksheet">'
  str << (    '<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>')
  str <<   '</cacheSource>'
  str << (  '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">')
  pivot_table.header_cells.each do |cell|
    str << (  '<cacheField name="' << cell.value << '" numFmtId="0">')
    str <<     '<sharedItems count="0">'
    str <<     '</sharedItems>'
    str <<   '</cacheField>'
  end
  str <<   '</cacheFields>'
  str << '</pivotCacheDefinition>'
end