summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-02-28 13:39:35 +0900
committerSean Duckett <[email protected]>2012-03-07 14:45:02 -0600
commitcc3cf0a1b89fb766278e924930ee7f87bd085a55 (patch)
treec4cdfcc5ab757313777a99ec578cf3ba8c0255e3
parent0257768200922b0dd33eb6e666824d53d61c035c (diff)
downloadcaxlsx-cc3cf0a1b89fb766278e924930ee7f87bd085a55.tar.gz
caxlsx-cc3cf0a1b89fb766278e924930ee7f87bd085a55.zip
referencing Converter, which is now known as DateTimeConverter.
This should have been caught in the specs, so I will update them later to make sure we cover this path.
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb80
1 files changed, 40 insertions, 40 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 167dfc97..dd3fddef 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -1,61 +1,61 @@
# encoding: UTF-8
module Axlsx
- # A cell in a worksheet.
+ # 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
+ # 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
# An array of available inline styes.
- INLINE_STYLES = ['value', 'type', 'font_name', 'charset',
- 'family', 'b', 'i', 'strike','outline',
- 'shadow', 'condense', 'extend', 'u',
+ INLINE_STYLES = ['value', 'type', 'font_name', 'charset',
+ 'family', 'b', 'i', 'strike','outline',
+ 'shadow', 'condense', 'extend', 'u',
'vertAlign', 'sz', 'color', 'scheme']
# The index of the cellXfs item to be applied to this cell.
- # @return [Integer]
+ # @return [Integer]
# @see Axlsx::Styles
attr_reader :style
# The row this cell belongs to.
# @return [Row]
attr_reader :row
-
+
# The cell's data type. Currently only six types are supported, :date, :time, :float, :integer, :string and :boolean.
- # Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is
+ # Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is
# automatically determed.
# @see Cell#cell_type_from_value
- # @return [Symbol] The type of data this cell's value is cast to.
+ # @return [Symbol] The type of data this cell's value is cast to.
# @raise [ArgumentExeption] Cell.type must be one of [:date, time, :float, :integer, :string, :boolean]
- # @note
+ # @note
# If the value provided cannot be cast into the type specified, type is changed to :string and the following logic is applied.
- # :string to :integer or :float, type conversions always return 0 or 0.0
+ # :string to :integer or :float, type conversions always return 0 or 0.0
# :string, :integer, or :float to :time conversions always return the original value as a string and set the cells type to :string.
# No support is currently implemented for parsing time strings.
attr_reader :type
# @see type
- def type=(v)
- RestrictionValidator.validate "Cell.type", [:date, :time, :float, :integer, :string, :boolean], v
- @type=v
+ def type=(v)
+ RestrictionValidator.validate "Cell.type", [:date, :time, :float, :integer, :string, :boolean], v
+ @type=v
self.value = @value unless @value.nil?
end
@@ -68,7 +68,7 @@ module Axlsx
#TODO: consider doing value based type determination first?
@value = cast_value(v)
end
-
+
# The inline font_name property for the cell
# @return [String]
attr_reader :font_name
@@ -139,7 +139,7 @@ module Axlsx
# @return [Color]
attr_reader :color
# @param [String] The 8 character representation for an rgb color #FFFFFFFF"
- def color=(v)
+ def color=(v)
@color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
end
@@ -164,7 +164,7 @@ module Axlsx
def scheme=(v) RestrictionValidator.validate "Cell.schema", [:none, :major, :minor], v; @scheme = v; end
# @param [Row] row The row this cell belongs to.
- # @param [Any] value The value associated with this cell.
+ # @param [Any] value The value associated with this cell.
# @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided.
# @option options [Integer] style The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied.
# @option options [String] font_name
@@ -183,11 +183,11 @@ 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={})
- self.row=row
+ self.row=row
@font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil
@condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil
@styles = row.worksheet.workbook.styles
- @row.cells << self
+ @row.cells << self
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
@@ -199,7 +199,7 @@ module Axlsx
# 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(v)
@@ -221,14 +221,14 @@ module Axlsx
# @return [String] The alpha(column)numeric(row) reference for this sell.
# @example Relative Cell Reference
- # ws.rows.first.cells.first.r #=> "A1"
+ # ws.rows.first.cells.first.r #=> "A1"
def r
- "#{col_ref}#{@row.index+1}"
+ "#{col_ref}#{@row.index+1}"
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"
+ # ws.rows.first.cells.first.r #=> "$A$1"
def r_abs
"$#{r.split('').join('$')}"
end
@@ -257,7 +257,7 @@ module Axlsx
target.r
end
self.row.worksheet.merge_cells "#{self.r}:#{range_end}" unless range_end.nil?
- end
+ end
# builds an xml text run based on this cells attributes. This is extracted from to_xml so that shared strings can use it.
# @param [Nokogiri::XML::Builder] xml The document builder instance this output will be added to.
@@ -288,14 +288,14 @@ module Axlsx
}
else
xml.t @value.to_s
- end
+ end
end
# Serializes the cell
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
# @return [String] xml text for the cell
- def to_xml(xml)
- if @type == :string
+ def to_xml(xml)
+ if @type == :string
#parse formula
if @value.start_with?('=')
xml.c(:r => r, :t=>:str, :s=>style) {
@@ -316,10 +316,10 @@ module Axlsx
end
elsif @type == :date
# TODO: See if this is subject to the same restriction as Time below
- v = Converter.date_to_serial @value, Workbook.date1904
+ v = DateTimeConverter.date_to_serial @value
xml.c(:r => r, :s => style) { xml.v v }
elsif @type == :time
- v = Converter.time_to_serial @value, Workbook.date1904
+ v = DateTimeConverter.time_to_serial @value
xml.c(:r => r, :s => style) { xml.v v }
elsif @type == :boolean
xml.c(:r => r, :s => style, :t => :b) { xml.v value }
@@ -328,17 +328,17 @@ module Axlsx
end
end
- private
+ private
# @see ssti
- def ssti=(v)
+ def ssti=(v)
Axlsx::validate_unsigned_int(v)
@ssti = v
end
# assigns the owning row for this cell.
def row=(v) DataTypeValidator.validate "Cell.row", Row, v; @row=v end
-
+
# converts the column index into alphabetical values.
# @note This follows the standard spreadsheet convention of naming columns A to Z, followed by AA to AZ etc.
# @return [String]
@@ -353,7 +353,7 @@ module Axlsx
chars.reverse.join
end
- # Determines the cell type based on the cell value.
+ # Determines the cell type based on the cell value.
# @note This is only used when a cell is created but no :type option is specified, the following rules apply:
# 1. If the value is an instance of Date, the type is set to :date
# 2. If the value is an instance of Time, the type is set to :time
@@ -361,7 +361,7 @@ module Axlsx
# 4. :float and :integer types are determined by regular expression matching.
# 5. Anything that does not meet either of the above is determined to be :string.
# @return [Symbol] The determined type
- def cell_type_from_value(v)
+ def cell_type_from_value(v)
if v.is_a?(Date)
:date
elsif v.is_a?(Time)
@@ -377,8 +377,8 @@ module Axlsx
end
end
- # Cast the value into this cells data type.
- # @note
+ # Cast the value into this cells data type.
+ # @note
# About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.
# @see Axlsx#date1904
def cast_value(v)
@@ -398,6 +398,6 @@ module Axlsx
@type = :string
v.to_s
end
- end
+ end
end
end