lib/axlsx.rb in axlsx-1.1.8 vs lib/axlsx.rb in axlsx-1.2.0
- old
+ new
@@ -37,19 +37,27 @@
end
end
# xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
module Axlsx
+
# determines the cell range for the items provided
- def self.cell_range(items)
- return "" unless items.first.is_a? Cell
- ref = "'#{items.first.row.worksheet.name}'!" +
- "#{items.first.r_abs}"
- ref += ":#{items.last.r_abs}" if items.size > 1
- ref
+ def self.cell_range(cells, absolute=true)
+ return "" unless cells.first.is_a? Cell
+ sort_cells(cells)
+ reference = "#{cells.first.reference(absolute)}:#{cells.last.reference(absolute)}"
+ absolute ? "'#{cells.first.row.worksheet.name}'!#{reference}" : reference
end
+ # sorts the array of cells provided to start from the minimum x,y to
+ # the maximum x.y#
+ # @param [Array] cells
+ # @return [Array]
+ def self.sort_cells(cells)
+ cells.sort { |x, y| [x.index, x.row.index] <=> [y.index, y.row.index] }
+ end
+
#global reference html entity encoding
# @return [HtmlEntities]
def self.coder
@@coder ||= ::HTMLEntities.new
end
@@ -58,12 +66,10 @@
def self.name_to_indices(name)
raise ArgumentError, 'invalid cell name' unless name.size > 1
v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val
end
-
[v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1]
-
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]