summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan (@morgan_randy) <[email protected]>2016-11-04 11:41:13 +0900
committerGitHub <[email protected]>2016-11-04 11:41:13 +0900
commit18fa7e7634a63259e4df0cce8005b38b4c2b4a3a (patch)
tree6e2419f7c89d0d2cd3ab260d59616690d0152f73 /lib
parentb7b65c0a49abceccda380222cd08bc28307e89f4 (diff)
parentc06ac853c57cf1aca2dd258915dd12003d9f9859 (diff)
downloadcaxlsx-18fa7e7634a63259e4df0cce8005b38b4c2b4a3a.tar.gz
caxlsx-18fa7e7634a63259e4df0cce8005b38b4c2b4a3a.zip
Merge pull request #455 from acl-services/text-type
Implement :text cell type
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb6
-rw-r--r--lib/axlsx/workbook/worksheet/cell_serializer.rb18
2 files changed, 18 insertions, 6 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index cd832f7b..777b7812 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -66,7 +66,7 @@ module Axlsx
:vertAlign, :sz, :color, :scheme].freeze
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
- :string, :boolean, :iso_8601].freeze
+ :string, :boolean, :iso_8601, :text].freeze
# The index of the cellXfs item to be applied to this cell.
# @return [Integer]
@@ -123,7 +123,7 @@ module Axlsx
# Indicates if the cell is good for shared string table
def plain_string?
- type == :string && # String typed
+ (type == :string || type == :text) && # String typed
!is_text_run? && # No inline styles
[email protected]? && # Not nil
[email protected]? && # Not empty
@@ -368,7 +368,7 @@ module Axlsx
# TODO find a better way to do this as it accounts for 30% of
# processing time in benchmarking...
def clean_value
- if type == :string && !Axlsx::trust_input
+ if (type == :string || type == :text) && !Axlsx::trust_input
Axlsx::sanitize(::CGI.escapeHTML(@value.to_s))
else
@value.to_s
diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb
index 9a9f9465..76a3c386 100644
--- a/lib/axlsx/workbook/worksheet/cell_serializer.rb
+++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -14,7 +14,7 @@ module Axlsx
method = cell.type
self.send(method, cell, str)
str << '</c>'
- end
+ end
# builds an xml text run based on this cells attributes.
# @param [String] str The string instance this run will be concated to.
@@ -22,7 +22,7 @@ module Axlsx
def run_xml_string(cell, str = '')
if cell.is_text_run?
valid = RichTextRun::INLINE_STYLES - [:value, :type]
- data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }]
+ data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }]
data = data.select { |key, value| valid.include?(key) && !value.nil? }
RichText.new(cell.value.to_s, data).to_xml_string(str)
elsif cell.contains_rich_text?
@@ -124,7 +124,7 @@ module Axlsx
inline_string_serialization cell, str
end
end
-
+
# Serializes cells that are of the type richtext
# @param [Cell] cell The cell that is being serialized
# @param [String] str The string the serialized content will be appended to.
@@ -137,6 +137,18 @@ module Axlsx
end
end
+ # Serializes cells that are of the type text
+ # @param [Cell] cell The cell that is being serialized
+ # @param [String] str The string the serialized content will be appended to.
+ # @return [String]
+ def text(cell, str)
+ if cell.ssti.nil?
+ inline_string_serialization cell, str
+ else
+ value_serialization 's', cell.ssti, str
+ end
+ end
+
private
def numeric(cell, str = '')