lib/axlsx.rb in axlsx-1.3.4 vs lib/axlsx.rb in axlsx-1.3.5
- old
+ new
@@ -102,15 +102,43 @@
# ws.rows.first.cells.first.r #=> "A1"
def self.cell_r(c_index, r_index)
Axlsx::col_ref(c_index).to_s << (r_index+1).to_s
end
+ # Creates an array of individual cell references based on an excel reference range.
+ # @param [String] range A cell range, for example A1:D5
+ # @return [Array]
+ def self.range_to_a(range)
+ range.match(/^(\w+?\d+)\:(\w+?\d+)$/)
+ start_col, start_row = name_to_indices($1)
+ end_col, end_row = name_to_indices($2)
+ (start_row..end_row).to_a.map do |row_num|
+ (start_col..end_col).to_a.map do |col_num|
+ "#{col_ref(col_num)}#{row_num+1}"
+ end
+ end
+ end
+
# performs the increadible feat of changing snake_case to CamelCase
# @param [String] s The snake case string to camelize
# @return [String]
def self.camel(s="", all_caps = true)
s = s.to_s
s = s.capitalize if all_caps
s.gsub(/_(.)/){ $1.upcase }
end
+
+ # Instructs the serializer to not try to escape cell value input.
+ # This will give you a huge speed bonus, but if you content has <, > or other xml character data
+ # the workbook will be invalid and excel will complain.
+ def self.trust_input
+ @trust_input ||= false
+ end
+
+ # @param[Boolean] trust_me A boolean value indicating if the cell value content is to be trusted
+ # @return [Boolean]
+ # @see Axlsx::trust_input
+ def self.trust_input=(trust_me)
+ @trust_input = trust_me
+ end
end