From cbfabd0dca2eb4f1b3af81bbaa7433246c5b198d Mon Sep 17 00:00:00 2001 From: Evan Hallmark Date: Mon, 7 Nov 2016 13:13:58 -0800 Subject: Added style_info field to pivot_table.rb --- lib/axlsx/workbook/worksheet/pivot_table.rb | 17 +++++++++++++++-- test/workbook/worksheet/tc_pivot_table.rb | 12 ++++++++++++ 2 files changed, 27 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 << "" data.each do |datum_value| # The correct name prefix in ["Sum","Average", etc...] - str << "" end str << '' end + # custom pivot table style + unless style_info.empty? + str << '' + end str << '' end diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb index a62e6f40..08ad49e6 100644 --- a/test/workbook/worksheet/tc_pivot_table.rb +++ b/test/workbook/worksheet/tc_pivot_table.rb @@ -67,6 +67,18 @@ class TestPivotTable < Test::Unit::TestCase assert_equal([{:ref=>"Sales", :subtotal => 'average'}], pivot_table.data) end + def test_add_pivot_table_with_style_info + style_info_data = { :name=>"PivotStyleMedium9", :showRowHeaders=>"1", :showLastColumn=>"0"} + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:style_info=>style_info_data}) do |pt| + pt.rows = ['Year', 'Month'] + pt.columns = ['Type'] + pt.data = ['Sales'] + pt.pages = ['Region'] + end + assert_equal(style_info_data, pivot_table.style_info) + shared_test_pivot_table_xml_validity(pivot_table) + end + def test_add_pivot_table_with_row_without_subtotals pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5', {:no_subtotals_on_headers=>['Year']}) do |pt| pt.data = ['Sales'] -- cgit v1.2.3