summaryrefslogtreecommitdiffhomepage
path: root/test/workbook
diff options
context:
space:
mode:
authorWeston Ganger <[email protected]>2022-01-13 08:06:07 -0800
committerJosef Šimánek <[email protected]>2022-01-28 20:31:04 +0100
commitc8eb5fe13bfca2dcac17848dd15dc04f4f0dcf9b (patch)
treead2e392d4113fd833a5f0de2914e91b98f4a5866 /test/workbook
parent9df7ea821ca36d66f15e34f857fb271f4b4dbc43 (diff)
downloadcaxlsx-c8eb5fe13bfca2dcac17848dd15dc04f4f0dcf9b.tar.gz
caxlsx-c8eb5fe13bfca2dcac17848dd15dc04f4f0dcf9b.zip
Fix invalid xml when pivot table created with more than one column in data field
Diffstat (limited to 'test/workbook')
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index a494dcfd..591f0ba9 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -140,4 +140,41 @@ class TestPivotTable < Test::Unit::TestCase
doc = Nokogiri::XML(pivot_table.to_xml_string)
assert_equal('4', doc.at_css('dataFields dataField')['numFmtId'], 'adding format options to pivot_table')
end
+
+ def test_pivot_table_with_more_than_one_data_row
+ ### https://github.com/caxlsx/caxlsx/issues/110
+
+ pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
+ pt.rows = ["Date", "Name"]
+ pt.data = [
+ {ref: "Gross amount", num_fmt: 2},
+ {ref: "Net amount", num_fmt: 2},
+ ]
+ end
+
+ xml = pivot_table.to_xml_string
+
+ assert(xml.include?('colFields'))
+
+ assert(!xml.include?('dataOnRows'))
+ assert(!xml.include?('colItems'))
+ end
+
+ def test_pivot_table_with_only_one_data_row
+ ### https://github.com/caxlsx/caxlsx/issues/110
+
+ pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
+ pt.rows = ["Date", "Name"]
+ pt.data = [
+ {ref: "Gross amount", num_fmt: 2},
+ ]
+ end
+
+ xml = pivot_table.to_xml_string
+
+ assert(xml.include?('dataOnRows'))
+ assert(xml.include?('colItems'))
+
+ assert(!xml.include?('colFields'))
+ end
end