lib/axlsx/workbook/worksheet/cell.rb in axlsx-1.0.13 vs lib/axlsx/workbook/worksheet/cell.rb in axlsx-1.0.14
- old
+ new
@@ -217,10 +217,22 @@
# @return [Array] of x/y coordinates in the cheet for this cell.
def pos
[index, row.index]
end
+ # Merges all the cells in a range created between this cell and the cell or string name for a cell provided
+ # @see worksheet.merge_cells
+ # @param [Cell, String] target The last cell, or str ref for the cell in the merge range
+ def merge(target)
+ range_end = if target.is_a?(String)
+ target
+ elsif(target.is_a?(Cell))
+ target.r
+ end
+ self.row.worksheet.merge_cells "#{self.r}:#{range_end}" unless range_end.nil?
+ 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
# @note
# Shared Strings are not used in this library. All values are set directly in the each sheet.
@@ -264,10 +276,18 @@
xml.t @value.to_s
}
}
}
end
+ elsif @type == :time
+ # Using hardcoded offsets here as some operating systems will not except a 'negative' offset from the ruby epoc.
+ # (1970)
+ epoc1900 = -2209021200 #Time.local(1900, 1, 1)
+ epoc1904 = -2082877200 #Time.local(1904, 1, 1)
+ epoc = Workbook.date1904 ? epoc1904 : epoc1900
+ v = ((@value.localtime.to_f - epoc) /60.0/60.0/24.0).to_f
+ xml.c(:r => r, :s => style) { xml.v v }
else
xml.c(:r => r, :s => style) { xml.v value }
end
end
@@ -313,18 +333,11 @@
# @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)
if (@type == :time && v.is_a?(Time)) || (@type == :time && v.respond_to?(:to_time))
- v = v.respond_to?(:to_time) ? v.to_time : v
self.style = STYLE_DATE if self.style == 0
- # Using hardcoded offsets here as some operating systems will not except a 'negative' offset from the ruby epoc.
- # (1970)
- epoc1900 = -2209021200 #Time.local(1900, 1, 1)
- epoc1904 = -2082877200 #Time.local(1904, 1, 1)
- epoc = Workbook.date1904 ? epoc1904 : epoc1900
- v = ((v.localtime.to_f - epoc) /60.0/60.0/24.0).to_f
- ((v * 10**11).round.to_f / 10**11)
+ v.respond_to?(:to_time) ? v.to_time : v
elsif @type == :float
v.to_f
elsif @type == :integer
v.to_i
else