From 4278f88e5faa8e733409bb4256a01cc510f87570 Mon Sep 17 00:00:00 2001 From: Dan DeBruler Date: Tue, 28 Dec 2021 13:33:54 -0500 Subject: Return output stream in binmode --- lib/axlsx/package.rb | 2 +- test/tc_package.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index d9865a48..1b30c815 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -124,7 +124,7 @@ module Axlsx def to_stream(confirm_valid=false) return false unless !confirm_valid || self.validate.empty? Relationship.initialize_ids_cache - zip = write_parts(Zip::OutputStream.new(StringIO.new, true)) + zip = write_parts(Zip::OutputStream.new(StringIO.new.binmode, true)) stream = zip.close_buffer stream.rewind stream diff --git a/test/tc_package.rb b/test/tc_package.rb index f1ce0421..8dea7ccf 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -303,6 +303,8 @@ class TestPackage < Test::Unit::TestCase # this is just a roundabout guess for a package as it is build now # in testing. assert(stream.size > 80000) + # Stream (of zipped contents) should have appropriate default encoding + assert_equal(stream.external_encoding, Encoding::ASCII_8BIT) # Cached ids should be cleared assert(Axlsx::Relationship.ids_cache.empty?) end -- cgit v1.2.3 From 7f4045fc69683d51c7c3fbd6497cfadba4966484 Mon Sep 17 00:00:00 2001 From: Dan DeBruler Date: Fri, 21 Jan 2022 10:53:37 -0500 Subject: Check string encoding for validity _and_ value --- test/tc_package.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tc_package.rb b/test/tc_package.rb index 8dea7ccf..b98fa2f0 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -304,6 +304,7 @@ class TestPackage < Test::Unit::TestCase # in testing. assert(stream.size > 80000) # Stream (of zipped contents) should have appropriate default encoding + assert stream.string.valid_encoding? assert_equal(stream.external_encoding, Encoding::ASCII_8BIT) # Cached ids should be cleared assert(Axlsx::Relationship.ids_cache.empty?) -- cgit v1.2.3 From b7ebd233689beab182c10605b0691cb70ab69208 Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Tue, 25 Jan 2022 08:01:23 -0800 Subject: Remove Known Bugs Section in Readme --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 76079ada..34929c91 100644 --- a/README.md +++ b/README.md @@ -155,10 +155,6 @@ p.use_shared_strings = true p.serialize('simple.xlsx') ``` -## Known Bugs - -There’s a [list of known bugs](https://github.com/caxlsx/caxlsx/issues?q=label%3A%22known+bug%22). (If you want to contribute to caxlsx, this is a good place to start!) - ## Contributing See [CONTRIBUTING.md](https://github.com/caxlsx/caxlsx/blob/master/CONTRIBUTING.md) -- cgit v1.2.3 From c8eb5fe13bfca2dcac17848dd15dc04f4f0dcf9b Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Thu, 13 Jan 2022 08:06:07 -0800 Subject: Fix invalid xml when pivot table created with more than one column in data field --- CHANGELOG.md | 3 +++ lib/axlsx/workbook/worksheet/pivot_table.rb | 6 +++-- test/workbook/worksheet/tc_pivot_table.rb | 37 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9a0d429..9983d90d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ CHANGELOG --------- +- **Unreleased** + - [PR #123](https://github.com/caxlsx/caxlsx/pull/123) - Fix invalid xml when pivot table created with more than one column in data field. Solves [Issue #110](https://github.com/caxlsx/caxlsx/issues/110) + - **September.22.21**: 3.1.1 - [PR #107](https://github.com/caxlsx/caxlsx/pull/107) - Add overlap to bar charts - [PR #108](https://github.com/caxlsx/caxlsx/pull/108) - Fix gap depth and gap depth validators for bar charts and 3D bar charts diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index d8c630ec..bc500a8a 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -173,7 +173,9 @@ module Axlsx # @return [String] def to_xml_string(str = '') str << '' - str << ('') + + str << ('') + str << ('') str << ('') header_cell_values.each do |cell_value| @@ -195,7 +197,7 @@ module Axlsx end str << '' end - if columns.empty? + if columns.empty? && data.size <= 1 str << '' else str << ('') 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 -- cgit v1.2.3