summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-12-14 13:15:16 +0900
committerRandy Morgan <[email protected]>2012-12-14 13:16:04 +0900
commitb1600deadaafdb396c5cc7ca9d448e8adab8ac11 (patch)
treeba560b3826c22c51d37c515d6b0232bf2a4de94e /lib
parent890b404c8f748a332c8c0cbcfec6aa44b7384fa4 (diff)
downloadcaxlsx-b1600deadaafdb396c5cc7ca9d448e8adab8ac11.tar.gz
caxlsx-b1600deadaafdb396c5cc7ca9d448e8adab8ac11.zip
Added formula_values options and specs for sheet format pr.
This lets cache formula values and specify the default row height so that iOS and Max OSX previews render properly
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/row.rb11
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb1
3 files changed, 18 insertions, 4 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index cfcb6118..67b11633 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -28,11 +28,12 @@ module Axlsx
# @option options [Symbol] vertAlign must be one of :baseline, :subscript, :superscript
# @option options [Integer] sz
# @option options [String] color an 8 letter rgb specification
+ # @option options [Number] formula_value The value to cache for a formula cell.
# @option options [Symbol] scheme must be one of :none, major, :minor
def initialize(row, value="", options={})
self.row=row
@value = @font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil
- @condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil
+ @formula_value = @condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil
@styles = row.worksheet.workbook.styles
@row.cells << self
parse_options options
@@ -41,6 +42,10 @@ module Axlsx
@value = cast_value(value)
end
+ # this is the cached value for formula cells. If you want the values to render in iOS/Mac OSX preview
+ # you need to set this.
+ attr_accessor :formula_value
+
# An array of available inline styes.
# TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
# then move it out to a module so we can re-use in in other classes.
@@ -326,8 +331,9 @@ module Axlsx
when :string
#parse formula
- if @value.start_with?('=')
+ if is_formula?
str << 't="str"><f>' << @value.to_s.sub('=', '') << '</f>'
+ str << '<v>' << @formula_value.to_s << '</v>' if @formula_value
else
#parse shared
if @ssti
diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb
index 1b64b412..43c85b59 100644
--- a/lib/axlsx/workbook/worksheet/row.rb
+++ b/lib/axlsx/workbook/worksheet/row.rb
@@ -147,15 +147,24 @@ module Axlsx
def array_to_cells(values, options={})
values = values
DataTypeValidator.validate 'Row.array_to_cells', Array, values
- types, style = options.delete(:types), options.delete(:style)
+ types, style, formula_values = options.delete(:types), options.delete(:style), options.delete(:formula_values)
values.each_with_index do |value, index|
+
+ #WTF IS THIS PAP?
cell_style = style.is_a?(Array) ? style[index] : style
options[:style] = cell_style if cell_style
+
cell_type = types.is_a?(Array)? types[index] : types
options[:type] = cell_type if cell_type
+
+ formula_value = formula_values[index] if formula_values.is_a?(Array)
+ options[:formula_value] = formula_value if formula_value
+
Cell.new(self, value, options)
+
options.delete(:style)
options.delete(:type)
+ options.delete(:formula_value)
end
end
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index af2b2dfd..62d4e557 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -620,7 +620,6 @@ module Axlsx
raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)
end
-
def serializable_parts
[sheet_pr, dimension, sheet_view, sheet_format_pr, column_info,
sheet_data, sheet_calc_pr, @sheet_protection, protected_ranges,