summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorochko <[email protected]>2012-04-06 16:33:15 +0900
committerochko <[email protected]>2012-04-06 16:33:15 +0900
commit3431214a4feaa076ebc246552e5e61331d35c398 (patch)
treee560af73715bed412c4e4fd3427b00b681257ac7 /lib
parent78e2f076f0b0a1bbe651a3ce53075ae2cf778284 (diff)
downloadcaxlsx-3431214a4feaa076ebc246552e5e61331d35c398.tar.gz
caxlsx-3431214a4feaa076ebc246552e5e61331d35c398.zip
put only plain string cells in shared string table
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/stylesheet/color.rb5
-rw-r--r--lib/axlsx/workbook/shared_strings_table.rb8
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb19
3 files changed, 13 insertions, 19 deletions
diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb
index 497e2d4d..065eeb46 100644
--- a/lib/axlsx/stylesheet/color.rb
+++ b/lib/axlsx/stylesheet/color.rb
@@ -71,10 +71,5 @@ module Axlsx
end
str << "/>"
end
-
- def signature
- "#{@rgb}:#{auto}:#{@tint}"
- end
-
end
end
diff --git a/lib/axlsx/workbook/shared_strings_table.rb b/lib/axlsx/workbook/shared_strings_table.rb
index 90aefced..61402aec 100644
--- a/lib/axlsx/workbook/shared_strings_table.rb
+++ b/lib/axlsx/workbook/shared_strings_table.rb
@@ -29,12 +29,12 @@ module Axlsx
# Creates a new Shared Strings Table agains an array of cells
# @param [Array] cells This is an array of all of the cells in the workbook
def initialize(cells)
- cells = cells.flatten.reject { |c| c.type != :string || c.value.nil? || c.value.start_with?('=') }
@index = 0
- @count = cells.size
@unique_cells = {}
@shared_xml_string = ""
- resolve(cells)
+ shareable_cells = cells.flatten.select{ |cell| cell.plain_string? }
+ @count = shareable_cells.size
+ resolve(shareable_cells)
end
# Serializes the object
@@ -53,7 +53,7 @@ module Axlsx
# @return [Array] unique cells
def resolve(cells)
cells.each do |cell|
- cell_hash = cell.shareable_hash
+ cell_hash = cell.value
if index = @unique_cells[cell_hash]
cell.send :ssti=, index
else
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 262cab28..6979a6d1 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -74,13 +74,20 @@ module Axlsx
@value = cast_value(v)
end
-
# Indicates that the cell has one or more of the custom cell styles applied.
# @return [Boolean]
def is_text_run?
@is_text_run ||= false
end
+ # Indicates if the cell is good for shared string table
+ def plain_string?
+ @type == :string && # String typed
+ !@is_text_run && # No inline styles
+ [email protected]? && # Not nil
+ [email protected]? && # Not empty
+ [email protected]_with?('=') # Not a formula
+ end
# The inline font_name property for the cell
# @return [String]
@@ -203,7 +210,6 @@ module Axlsx
# @option options [String] color an 8 letter rgb specification
# @option options [Symbol] scheme must be one of :none, major, :minor
def initialize(row, value="", options={})
- @signature = 0
self.row=row
@font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil
@condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil
@@ -221,12 +227,6 @@ module Axlsx
# @return [Integer]
attr_reader :ssti
- # equality comparison to test value, type and inline style attributes
- # this is how we work out if the cell needs to be added or already exists in the shared strings table
- def shareable_hash
- "#{@signature} & #{@value} & #{@color && @color.signature}"
- end
-
# @return [Integer] The index of the cell in the containing row.
def index
@row.cells.index(self)
@@ -337,9 +337,8 @@ module Axlsx
# Utility method for setting inline style attributes
def set_run_style( validator, attr, value)
- return unless idx = INLINE_STYLES.index(attr.to_s)
+ return unless INLINE_STYLES.include?(attr.to_s)
Axlsx.send(validator, value) unless validator == nil
- @signature += 2**idx
self.instance_variable_set :"@#{attr.to_s}", value
@is_text_run = true
end