diff options
| author | Jean Jacques Warmerdam <[email protected]> | 2013-02-25 14:57:00 +0100 |
|---|---|---|
| committer | Jean Jacques Warmerdam <[email protected]> | 2013-02-25 14:57:00 +0100 |
| commit | 35d3cc8b21bce0c4ce7b9ec4e29d52df4b5f9cc4 (patch) | |
| tree | a527dd0066ee69c15c635d337a9c070c2db22933 /lib | |
| parent | 61488b068f220a32f4c5ab50a4108e61caa4d7aa (diff) | |
| download | caxlsx-35d3cc8b21bce0c4ce7b9ec4e29d52df4b5f9cc4.tar.gz caxlsx-35d3cc8b21bce0c4ce7b9ec4e29d52df4b5f9cc4.zip | |
Allow other sheet as data source for pivot tables and fix hard coded sheet name in Pivot Table Cache Definition
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/pivot_table.rb | 12 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb | 2 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index 4ebcdee8..94edf80e 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -19,6 +19,7 @@ module Axlsx @sheet = sheet @sheet.workbook.pivot_tables << self @name = "PivotTable#{index+1}" + @data_sheet = nil @rows = [] @columns = [] @data = [] @@ -39,6 +40,15 @@ module Axlsx # @return [String] attr_reader :sheet + # The sheet used as data source for the pivot table + # @return [Worksheet] + attr_writer :data_sheet + + # (see #data_sheet) + def data_sheet + @data_sheet || @sheet + end + # The range where the data for this pivot table lives. # @return [String] attr_reader :range @@ -206,7 +216,7 @@ module Axlsx # The header cells for the pivot table # @return [Array] def header_cells - @sheet[header_range] + data_sheet[header_range] end # The values in the header cells collection diff --git a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb index c1683520..37f46c51 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb @@ -48,7 +48,7 @@ module Axlsx 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="Data Sheet"/>' + 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| |
