summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorNoel Peden <[email protected]>2022-02-05 15:17:29 -0800
committerGitHub <[email protected]>2022-02-05 15:17:29 -0800
commite10ba950c6f09a5f2b1779ae103a2c044ce0615e (patch)
tree986b233b1a54990d007aeceb76ecfb6a4f2d346b /lib
parent34a287b33364657bc340e98be846b65fa8a77922 (diff)
parent540cf9bf59d333228b7e69f0a5c2e0cff06b5fca (diff)
downloadcaxlsx-e10ba950c6f09a5f2b1779ae103a2c044ce0615e.tar.gz
caxlsx-e10ba950c6f09a5f2b1779ae103a2c044ce0615e.zip
Merge branch 'master' into improve_range_error
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/package.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table.rb6
2 files changed, 5 insertions, 3 deletions
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/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 << '<?xml version="1.0" encoding="UTF-8"?>'
- str << ('<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '" dataOnRows="1" applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">')
+
+ str << ('<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '"' << (data.size <= 1 ? ' dataOnRows="1"' : '') << ' applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">')
+
str << ('<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>')
str << ('<pivotFields count="' << header_cells_count.to_s << '">')
header_cell_values.each do |cell_value|
@@ -195,7 +197,7 @@ module Axlsx
end
str << '</rowItems>'
end
- if columns.empty?
+ if columns.empty? && data.size <= 1
str << '<colItems count="1"><i/></colItems>'
else
str << ('<colFields count="' << columns.size.to_s << '">')