lib/axlsx/workbook/worksheet/cell.rb in axlsx-1.1.0 vs lib/axlsx/workbook/worksheet/cell.rb in axlsx-1.1.1
- old
+ new
@@ -1,26 +1,10 @@
# encoding: UTF-8
require 'cgi'
module Axlsx
# A cell in a worksheet.
# Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
- # @example Manually creating and manipulating Cell objects
- # ws = Workbook.new.add_worksheet
- # # This is the simple, and recommended way to create cells. Data types will automatically be determined for you.
- # ws.add_row :values => [1,"fish",Time.now]
- #
- # # but you can also do this
- # r = ws.add_row
- # r.add_cell 1
- #
- # # or even this
- # r = ws.add_row
- # c = Cell.new row, 1, :value=>integer
- #
- # # cells can also be accessed via Row#cells. The example here changes the cells type, which will automatically updated the value from 1 to 1.0
- # r.cells.last.type = :float
- #
# @note The recommended way to generate cells is via Worksheet#add_row
#
# @see Worksheet#add_row
class Cell
@@ -72,17 +56,24 @@
def value=(v)
#TODO: consider doing value based type determination first?
@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
+ !@value.nil? && # Not nil
+ !@value.empty? && # Not empty
+ !@value.start_with?('=') # Not a formula
+ end
# The inline font_name property for the cell
# @return [String]
attr_reader :font_name
# @see font_name
@@ -152,11 +143,11 @@
# @return [Color]
attr_reader :color
# @param [String] The 8 character representation for an rgb color #FFFFFFFF"
def color=(v)
@color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
- @has_run_style = true
+ @is_text_run = true
end
# The inline sz property for the cell
# @return [Boolean]
attr_reader :sz
@@ -218,29 +209,19 @@
# The Shared Strings Table index for this cell
# @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
- self_hash = {}
- INLINE_STYLES.each { |style| self_hash[style] = self.instance_variable_get("@" + style) }
- self_hash['color'] = self_hash['color'].instance_values if self_hash['color']
- self_hash
- end
-
# @return [Integer] The index of the cell in the containing row.
def index
@row.cells.index(self)
end
# @return [String] The alpha(column)numeric(row) reference for this sell.
# @example Relative Cell Reference
# ws.rows.first.cells.first.r #=> "A1"
- # @note this will be discontinued in 1.1.0 - prefer Axlsx.cell_r
def r
- "#{Axlsx::col_ref(index)}#{@row.index+1}"
+ Axlsx::cell_r index, @row.index
end
# @return [String] The absolute alpha(column)numeric(row) reference for this sell.
# @example Absolute Cell Reference
# ws.rows.first.cells.first.r #=> "$A$1"