summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJurriaan Pruis <[email protected]>2014-04-04 11:39:25 +0200
committerJurriaan Pruis <[email protected]>2014-04-04 11:39:25 +0200
commit5ccab460b65f597398f1d8a1b2a5a83039b80a9e (patch)
tree6fa3a9e38f81e6f59693acf8861b12938d0030bf /lib
parentc649ee7d5ac699d0fc5a36550f502216f9b7318f (diff)
downloadcaxlsx-5ccab460b65f597398f1d8a1b2a5a83039b80a9e.tar.gz
caxlsx-5ccab460b65f597398f1d8a1b2a5a83039b80a9e.zip
Fix boolean values so the output matches Excel and works on Numbers
Use 1 or 0 instead of 'true' or 'false' in the XML output
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx.rb12
-rw-r--r--lib/axlsx/stylesheet/font.rb3
-rw-r--r--lib/axlsx/util/serialized_attributes.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/data_validation.rb4
4 files changed, 19 insertions, 2 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index b5df5916..c6f01b19 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -137,6 +137,18 @@ module Axlsx
str.delete!(CONTROL_CHARS)
str
end
+
+ # If value is boolean return 1 or 0
+ # else return the value
+ # @param [Object] value The value to process
+ # @return [Object]
+ def self.booleanize(value)
+ if value == true || value == false
+ value ? 1 : 0
+ else
+ value
+ end
+ end
# Instructs the serializer to not try to escape cell value input.
# This will give you a huge speed bonus, but if you content has <, > or other xml character data
diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb
index 6d77d58b..8770297d 100644
--- a/lib/axlsx/stylesheet/font.rb
+++ b/lib/axlsx/stylesheet/font.rb
@@ -140,6 +140,9 @@ module Axlsx
def to_xml_string(str = '')
str << '<font>'
instance_values.each do |k, v|
+ if v == true || v == false
+ v = v ? 1 : 0
+ end
v.is_a?(Color) ? v.to_xml_string(str) : (str << ('<' << k.to_s << ' val="' << v.to_s << '"/>'))
end
str << '</font>'
diff --git a/lib/axlsx/util/serialized_attributes.rb b/lib/axlsx/util/serialized_attributes.rb
index 0b71c70b..d6b5d3c7 100644
--- a/lib/axlsx/util/serialized_attributes.rb
+++ b/lib/axlsx/util/serialized_attributes.rb
@@ -52,7 +52,7 @@ module Axlsx
def serialized_attributes(str = '', additional_attributes = {})
attributes = declared_attributes.merge! additional_attributes
attributes.each do |key, value|
- str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(value, false)}\" "
+ str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\" "
end
str
end
diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb
index 67aef4e5..ab018695 100644
--- a/lib/axlsx/workbook/worksheet/data_validation.rb
+++ b/lib/axlsx/workbook/worksheet/data_validation.rb
@@ -216,7 +216,9 @@ module Axlsx
valid_attributes = get_valid_attributes
str << '<dataValidation '
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' if (valid_attributes.include?(key.to_sym) and not CHILD_ELEMENTS.include?(key.to_sym)) }.join(' ')
+ str << instance_values.map do |key, value|
+ '' << key << '="' << Axlsx.booleanize(value).to_s << '"' if (valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym))
+ end.join(' ')
str << '>'
str << ('<formula1>' << self.formula1 << '</formula1>') if @formula1 and valid_attributes.include?(:formula1)
str << ('<formula2>' << self.formula2 << '</formula2>') if @formula2 and valid_attributes.include?(:formula2)