summaryrefslogtreecommitdiffhomepage
path: root/test/workbook
diff options
context:
space:
mode:
authorKnut Stenmark <[email protected]>2022-07-21 16:17:46 +0200
committerKnut Stenmark <[email protected]>2022-07-21 16:17:46 +0200
commitf2a4b5a4342226650ca0d8618b43ccbe7b267925 (patch)
tree53acbf733934bf952f33abc20ae94fa89513e1f6 /test/workbook
parente975a2451ae3c5f6eb62bfbfea33be3bb9f2cb14 (diff)
downloadcaxlsx-f2a4b5a4342226650ca0d8618b43ccbe7b267925.tar.gz
caxlsx-f2a4b5a4342226650ca0d8618b43ccbe7b267925.zip
Prevent Excel from crashing when multiple data columns are added to PivotTable
Excel will crash unless both `colFields` and `colItems` are declared in the PivotTable xml. First `field` of `colFields` needs to be set to -2 to tell Excel that the value columns comes from individual columns and not groups. I do not know why `colItems` are needed, but when set, the Excel document opens without crashing.
Diffstat (limited to 'test/workbook')
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index c7aa53cc..f676a72d 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -162,15 +162,27 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = [
{ref: "Gross amount", num_fmt: 2},
{ref: "Net amount", num_fmt: 2},
+ {ref: "Margin", num_fmt: 2},
]
end
xml = pivot_table.to_xml_string
+ assert(!xml.include?('dataOnRows'))
assert(xml.include?('colFields'))
+ assert(xml.include?('colItems'))
+
+ doc = Nokogiri::XML(pivot_table.to_xml_string)
+
+ assert_equal('1', doc.at_css('colFields')['count'])
+ assert_equal('-2', doc.at_css('colFields field')['x'])
+
+ assert_equal('3', doc.at_css('colItems')['count'])
+ assert_equal( 3, doc.at_css('colItems').children.size)
+ assert_nil( doc.at_css('colItems i')['x'])
+ assert_equal('1', doc.at_css('colItems i[i=1] x')['v'])
+ assert_equal('2', doc.at_css('colItems i[i=2] x')['v'])
- assert(!xml.include?('dataOnRows'))
- assert(!xml.include?('colItems'))
end
def test_pivot_table_with_only_one_data_row