summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/pivot_table.rb
diff options
context:
space:
mode:
authorEvan Hallmark <[email protected]>2016-11-07 13:13:58 -0800
committerEvan Hallmark <[email protected]>2016-11-07 13:13:58 -0800
commitcbfabd0dca2eb4f1b3af81bbaa7433246c5b198d (patch)
tree4865723e76d23006489feeeec5b3f67db5d64490 /lib/axlsx/workbook/worksheet/pivot_table.rb
parent90b69543ccad773ffff581dd929d94502e45cae9 (diff)
downloadcaxlsx-cbfabd0dca2eb4f1b3af81bbaa7433246c5b198d.tar.gz
caxlsx-cbfabd0dca2eb4f1b3af81bbaa7433246c5b198d.zip
Added style_info field to pivot_table.rb
Diffstat (limited to 'lib/axlsx/workbook/worksheet/pivot_table.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb
index 7dac7aa3..fffced0b 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table.rb
@@ -26,6 +26,7 @@ module Axlsx
@pages = []
@subtotal = nil
@no_subtotals_on_headers = []
+ @style_info = {}
parse_options options
yield self if block_given?
end
@@ -34,6 +35,10 @@ module Axlsx
# @return[Array]
attr_accessor :no_subtotals_on_headers
+ # Style info for the pivot table
+ # @return[Hash]
+ attr_accessor :style_info
+
# The reference to the table data
# @return [String]
attr_reader :ref
@@ -206,12 +211,20 @@ module Axlsx
str << "<dataFields count=\"#{data.size}\">"
data.each do |datum_value|
# The correct name prefix in ["Sum","Average", etc...]
- str << "<dataField name=\"#{(datum_value[:subtotal]||'')} of #{datum_value[:ref]}\" fld=\"#{header_index_of(datum_value[:ref])}\" baseField=\"0\" baseItem=\"0\""
- str << " subtotal=\"#{datum_value[:subtotal]}\" " if datum_value[:subtotal]
+ str << "<dataField name='#{(datum_value[:subtotal]||'')} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
+ str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal]
str << "/>"
end
str << '</dataFields>'
end
+ # custom pivot table style
+ unless style_info.empty?
+ str << '<pivotTableStyleInfo'
+ style_info.each do |k,v|
+ str << ' ' << k.to_s << '="' << v.to_s << '"'
+ end
+ str << ' />'
+ end
str << '</pivotTableDefinition>'
end