summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/axlsx/workbook/worksheet')
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb65
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb51
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb56
-rw-r--r--lib/axlsx/workbook/worksheet/border_creator.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb50
-rw-r--r--lib/axlsx/workbook/worksheet/cell_serializer.rb14
-rw-r--r--lib/axlsx/workbook/worksheet/cfvo.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/color_scale.rb8
-rw-r--r--lib/axlsx/workbook/worksheet/comment.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/comments.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/conditional_formatting.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb30
-rw-r--r--lib/axlsx/workbook/worksheet/data_bar.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/data_validation.rb30
-rw-r--r--lib/axlsx/workbook/worksheet/date_time_converter.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/icon_set.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/merged_cells.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/page_margins.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/page_setup.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/pane.rb14
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table.rb8
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/protected_ranges.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text_run.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/row.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/row_breaks.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/selection.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_protection.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_view.rb16
-rw-r--r--lib/axlsx/workbook/worksheet/table.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/table_style_info.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb34
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_comments.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_drawing.rb6
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb4
35 files changed, 322 insertions, 156 deletions
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
index f25966de..586dc711 100644
--- a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
+++ b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
@@ -2,6 +2,7 @@
require 'axlsx/workbook/worksheet/auto_filter/filter_column'
require 'axlsx/workbook/worksheet/auto_filter/filters'
+require 'axlsx/workbook/worksheet/auto_filter/sort_state'
module Axlsx
# This class represents an auto filter range in a worksheet
@@ -12,9 +13,10 @@ module Axlsx
raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
@worksheet = worksheet
+ @sort_on_generate = true
end
- attr_reader :worksheet
+ attr_reader :worksheet, :sort_on_generate
# The range the autofilter should be applied to.
# This should be a string like 'A1:B8'
@@ -48,15 +50,50 @@ module Axlsx
columns.last
end
- # actually performs the filtering of rows who's cells do not
- # match the filter.
+ # Performs the sorting of the rows based on the sort_state conditions. Then it actually performs
+ # the filtering of rows who's cells do not match the filter.
def apply
first_cell, last_cell = range.split(':')
- start_point = Axlsx::name_to_indices(first_cell)
- end_point = Axlsx::name_to_indices(last_cell)
+ start_point = Axlsx.name_to_indices(first_cell)
+ end_point = Axlsx.name_to_indices(last_cell)
# The +1 is so we skip the header row with the filter drop downs
rows = worksheet.rows[(start_point.last + 1)..end_point.last] || []
+ # the sorting of the rows if sort_conditions are available.
+ if !sort_state.sort_conditions.empty? && sort_on_generate
+ sort_conditions = sort_state.sort_conditions
+ sorted_rows = rows.sort do |row1, row2|
+ comparison = 0
+
+ sort_conditions.each do |condition|
+ cell_value_row1 = row1.cells[condition.column_index + start_point.first].value
+ cell_value_row2 = row2.cells[condition.column_index + start_point.first].value
+ custom_list = condition.custom_list
+ comparison = if cell_value_row1.nil? || cell_value_row2.nil?
+ cell_value_row1.nil? ? 1 : -1
+ elsif custom_list.empty?
+ condition.order == :asc ? cell_value_row1 <=> cell_value_row2 : cell_value_row2 <=> cell_value_row1
+ else
+ index1 = custom_list.index(cell_value_row1) || custom_list.size
+ index2 = custom_list.index(cell_value_row2) || custom_list.size
+
+ condition.order == :asc ? index1 <=> index2 : index2 <=> index1
+ end
+
+ break unless comparison.zero?
+ end
+
+ comparison
+ end
+ insert_index = start_point.last + 1
+
+ sorted_rows.each do |row|
+ # Insert the row at the specified index
+ worksheet.rows[insert_index] = row
+ insert_index += 1
+ end
+ end
+
column_offset = start_point.first
columns.each do |column|
rows.each do |row|
@@ -67,6 +104,21 @@ module Axlsx
end
end
+ # the SortState object for this AutoFilter
+ # @return [SortState]
+ def sort_state
+ @sort_state ||= SortState.new self
+ end
+
+ # @param [Boolean] v Flag indicating whether the AutoFilter should sort the rows when generating the
+ # file. If false, the sorting rules will need to be applied manually after generating to alter
+ # the order of the rows.
+ # @return [Boolean]
+ def sort_on_generate=(v)
+ Axlsx.validate_boolean v
+ @sort_on_generate = v
+ end
+
# serialize the object
# @return [String]
def to_xml_string(str = +'')
@@ -74,6 +126,9 @@ module Axlsx
str << "<autoFilter ref='#{range}'>"
columns.each { |filter_column| filter_column.to_xml_string(str) }
+ unless @sort_state.nil?
+ @sort_state.to_xml_string(str)
+ end
str << "</autoFilter>"
end
end
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb b/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb
new file mode 100644
index 00000000..8704dbdd
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+module Axlsx
+ # This class represents a individual sort condition belonging to the sort state of an auto filter
+ class SortCondition
+ # Creates a new SortCondition object
+ # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
+ # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
+ # @param [Array] custom_list An array containg a custom sorting list in order.
+ def initialize(column_index:, order:, custom_list:)
+ Axlsx.validate_int column_index
+ @column_index = column_index
+
+ RestrictionValidator.validate 'SortCondition.order', [:asc, :desc], order
+ @order = order
+
+ DataTypeValidator.validate :sort_condition_custom_list, Array, custom_list
+ @custom_list = custom_list
+ end
+
+ attr_reader :column_index, :order, :custom_list
+
+ # converts the ref String from the sort_state to a string representing the ref of a single column
+ # for the xml string to be returned.
+ def ref_to_single_column(ref, column_index)
+ first_cell, last_cell = ref.split(':')
+
+ start_point = Axlsx.name_to_indices(first_cell)
+
+ first_row = first_cell[/\d+/]
+ last_row = last_cell[/\d+/]
+
+ first_column = Axlsx.col_ref(column_index + start_point.first)
+ last_column = first_column
+
+ "#{first_column}#{first_row}:#{last_column}#{last_row}"
+ end
+
+ # serialize the object
+ # @return [String]
+ def to_xml_string(str, ref)
+ ref = ref_to_single_column(ref, column_index)
+
+ str << "<sortCondition "
+ str << "descending='1' " if order == :desc
+ str << "ref='#{ref}' "
+ str << "customList='#{custom_list.join(',')}' " unless custom_list.empty?
+ str << "/>"
+ end
+ end
+end
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb b/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb
new file mode 100644
index 00000000..71e03b00
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require 'axlsx/workbook/worksheet/auto_filter/sort_condition'
+
+module Axlsx
+ # This class performs sorting on a range in a worksheet
+ class SortState
+ # creates a new SortState object
+ # @param [AutoFilter] auto_filter the auto_filter that this sort_state belongs to
+ def initialize(auto_filter)
+ @auto_filter = auto_filter
+ end
+
+ # A collection of SortConditions for this sort_state
+ # @return [SimpleTypedList]
+ def sort_conditions
+ @sort_conditions ||= SimpleTypedList.new SortCondition
+ end
+
+ # Adds a SortCondition to the sort_state. This is the recommended way to add conditions to it.
+ # It requires a column_index for the sorting, descending and the custom order are optional.
+ # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
+ # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
+ # @param [Array] custom_list An array containg a custom sorting list in order.
+ # @return [SortCondition]
+ def add_sort_condition(column_index:, order: :asc, custom_list: [])
+ sort_conditions << SortCondition.new(column_index: column_index, order: order, custom_list: custom_list)
+ sort_conditions.last
+ end
+
+ # method to increment the String representing the first cell of the range of the autofilter by 1 row for the sortCondition
+ # xml string
+ def increment_cell_value(str)
+ letter = str[/[A-Za-z]+/]
+ number = str[/\d+/].to_i
+
+ incremented_number = number + 1
+
+ "#{letter}#{incremented_number}"
+ end
+
+ # serialize the object
+ # @return [String]
+ def to_xml_string(str = +'')
+ return if sort_conditions.empty?
+
+ ref = @auto_filter.range
+ first_cell, last_cell = ref.split(':')
+ ref = "#{increment_cell_value(first_cell)}:#{last_cell}"
+
+ str << "<sortState xmlns:xlrd2='http://schemas.microsoft.com/office/spreadsheetml/2017/richdata2' ref='#{ref}'>"
+ sort_conditions.each { |sort_condition| sort_condition.to_xml_string(str, ref) }
+ str << "</sortState>"
+ end
+ end
+end
diff --git a/lib/axlsx/workbook/worksheet/border_creator.rb b/lib/axlsx/workbook/worksheet/border_creator.rb
index 9abaded5..04a9cfac 100644
--- a/lib/axlsx/workbook/worksheet/border_creator.rb
+++ b/lib/axlsx/workbook/worksheet/border_creator.rb
@@ -17,7 +17,7 @@ module Axlsx
else
@edges = @edges.map { |x| x&.to_sym }.uniq
- if !(@edges - Axlsx::Border::EDGES).empty?
+ unless (@edges - Axlsx::Border::EDGES).empty?
raise ArgumentError, "Invalid edges provided, #{edges}"
end
end
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index f651e3cb..2ff3a3cc 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true
-require 'cgi'
module Axlsx
# 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.
@@ -48,7 +47,7 @@ module Axlsx
val = options.delete(:escape_formulas)
self.escape_formulas = val unless val.nil?
- parse_options(options)
+ parse_options(options) unless options.empty?
self.value = value
value.cell = self if contains_rich_text?
@@ -167,7 +166,7 @@ module Axlsx
# Indicates that the cell has one or more of the custom cell styles applied.
# @return [Boolean]
- def is_text_run?
+ def is_text_run? # rubocop:disable Naming/PredicateName
defined?(@is_text_run) && @is_text_run && !contains_rich_text?
end
@@ -177,12 +176,12 @@ module Axlsx
# Indicates if the cell is good for shared string table
def plain_string?
- (type == :string || type == :text) && # String typed
- !is_text_run? && # No inline styles
- [email protected]? && # Not nil
- [email protected]? && # Not empty
- !is_formula? && # Not a formula
- !is_array_formula? # Not an array formula
+ (type == :string || type == :text) && # String typed
+ !value.nil? &&
+ !value.empty? &&
+ !is_text_run? && # No inline styles
+ !is_formula? &&
+ !is_array_formula?
end
# The inline font_name property for the cell
@@ -345,7 +344,7 @@ module Axlsx
# @example Relative Cell Reference
# ws.rows.first.cells.first.r #=> "A1"
def r
- Axlsx::cell_r index, @row.row_index
+ Axlsx.cell_r index, @row.row_index
end
# @return [String] The absolute alpha(column)numeric(row) reference for this cell.
@@ -358,7 +357,7 @@ module Axlsx
# @return [Integer] The cellXfs item index applied to this cell.
# @raise [ArgumentError] Invalid cellXfs id if the value provided is not within cellXfs items range.
def style=(v)
- Axlsx::validate_unsigned_int(v)
+ Axlsx.validate_unsigned_int(v)
count = styles.cellXfs.size
raise ArgumentError, "Invalid cellXfs id" unless v < count
@@ -375,11 +374,11 @@ module Axlsx
# @param [Cell, String] target The last cell, or str ref for the cell in the merge range
def merge(target)
start, stop = if target.is_a?(String)
- [self.r, target]
+ [r, target]
elsif target.is_a?(Cell)
Axlsx.sort_cells([self, target]).map(&:r)
end
- self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
+ row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
end
# Serializes the cell
@@ -391,13 +390,13 @@ module Axlsx
CellSerializer.to_xml_string r_index, c_index, self, str
end
- def is_formula?
+ def is_formula? # rubocop:disable Naming/PredicateName
return false if escape_formulas
type == :string && @value.to_s.start_with?(FORMULA_PREFIX)
end
- def is_array_formula?
+ def is_array_formula? # rubocop:disable Naming/PredicateName
return false if escape_formulas
type == :string &&
@@ -426,7 +425,7 @@ module Axlsx
# Attempts to determine the correct width for this cell's content
# @return [Float]
def autowidth
- return if is_formula? || value.nil?
+ return if value.nil? || is_formula?
if contains_rich_text?
string_width('', font_size) + value.autowidth
@@ -442,12 +441,13 @@ module Axlsx
end
end
- # Returns the sanatized value
- # TODO find a better way to do this as it accounts for 30% of
+ # Returns the sanitized value
+ # TODO: find a better way to do this as it accounts for 30% of
# processing time in benchmarking...
+ # @return [String] The sanitized value
def clean_value
- if (type == :string || type == :text) && !Axlsx::trust_input
- Axlsx::sanitize(::CGI.escapeHTML(@value.to_s))
+ if (type == :string || type == :text) && !Axlsx.trust_input
+ Axlsx.sanitize(::CGI.escapeHTML(@value.to_s))
else
@value.to_s
end
@@ -482,13 +482,13 @@ module Axlsx
return unless INLINE_STYLES.include?(attr.to_sym)
Axlsx.send(validator, value) unless validator.nil?
- self.instance_variable_set :"@#{attr}", value
+ instance_variable_set :"@#{attr}", value
@is_text_run = true
end
# @see ssti
def ssti=(v)
- Axlsx::validate_unsigned_int(v)
+ Axlsx.validate_unsigned_int(v)
@ssti = v
end
@@ -525,18 +525,18 @@ module Axlsx
# 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)
- return v if v.is_a?(RichText) || v.nil?
+ return v if v.nil? || v.is_a?(RichText)
case type
when :date
- self.style = STYLE_DATE if self.style.zero?
+ self.style = STYLE_DATE if style.zero?
if !v.is_a?(Date) && v.respond_to?(:to_date)
v.to_date
else
v
end
when :time
- self.style = STYLE_DATE if self.style.zero?
+ self.style = STYLE_DATE if style.zero?
if !v.is_a?(Time) && v.respond_to?(:to_time)
v.to_time
else
diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb
index 30a2b5fe..2124a7f4 100644
--- a/lib/axlsx/workbook/worksheet/cell_serializer.rb
+++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -11,12 +11,12 @@ module Axlsx
# @return [String]
def to_xml_string(row_index, column_index, cell, str = +'')
str << '<c r="'
- str << Axlsx::col_ref(column_index) << Axlsx::row_ref(row_index)
+ str << Axlsx.col_ref(column_index) << Axlsx.row_ref(row_index)
str << '" s="' << cell.style_str << '" '
return str << '/>' if cell.value.nil?
method = cell.type
- self.send(method, cell, str)
+ send(method, cell, str)
str << '</c>'
end
@@ -27,7 +27,7 @@ module Axlsx
if cell.is_text_run?
valid = RichTextRun::INLINE_STYLES - [:value, :type]
data = Axlsx.instance_values_for(cell).transform_keys(&:to_sym)
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
RichText.new(cell.value.to_s, data).to_xml_string(str)
elsif cell.contains_rich_text?
cell.value.to_xml_string(str)
@@ -50,7 +50,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def date(cell, str = +'')
- value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str
+ value_serialization false, DateTimeConverter.date_to_serial(cell.value).to_s, str
end
# Serializes cells that are type time
@@ -58,7 +58,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def time(cell, str = +'')
- value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str
+ value_serialization false, DateTimeConverter.time_to_serial(cell.value).to_s, str
end
# Serializes cells that are type boolean
@@ -90,7 +90,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def formula_serialization(cell, str = +'')
- str << 't="str"><f>' << cell.clean_value.to_s.delete_prefix(FORMULA_PREFIX) << '</f>'
+ str << 't="str"><f>' << cell.clean_value.delete_prefix(FORMULA_PREFIX) << '</f>'
str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
end
@@ -99,7 +99,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def array_formula_serialization(cell, str = +'')
- str << 't="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.delete_prefix(ARRAY_FORMULA_PREFIX).delete_suffix(ARRAY_FORMULA_SUFFIX) << '</f>'
+ str << 't="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.delete_prefix(ARRAY_FORMULA_PREFIX).delete_suffix(ARRAY_FORMULA_SUFFIX) << '</f>'
str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
end
diff --git a/lib/axlsx/workbook/worksheet/cfvo.rb b/lib/axlsx/workbook/worksheet/cfvo.rb
index 9aeb55ed..71985896 100644
--- a/lib/axlsx/workbook/worksheet/cfvo.rb
+++ b/lib/axlsx/workbook/worksheet/cfvo.rb
@@ -40,10 +40,10 @@ module Axlsx
attr_reader :val
# @see type
- def type=(v); Axlsx::validate_conditional_formatting_value_object_type(v); @type = v end
+ def type=(v); Axlsx.validate_conditional_formatting_value_object_type(v); @type = v end
# @see gte
- def gte=(v); Axlsx::validate_boolean(v); @gte = v end
+ def gte=(v); Axlsx.validate_boolean(v); @gte = v end
# @see val
def val=(v)
diff --git a/lib/axlsx/workbook/worksheet/color_scale.rb b/lib/axlsx/workbook/worksheet/color_scale.rb
index e48de3bb..84ece25b 100644
--- a/lib/axlsx/workbook/worksheet/color_scale.rb
+++ b/lib/axlsx/workbook/worksheet/color_scale.rb
@@ -22,7 +22,7 @@ module Axlsx
# color_scale = Axlsx::ColorScale.two_tone
# @see examples/example.rb conditional formatting examples.
def two_tone
- self.new
+ new
end
# A builder for three tone color gradient
@@ -31,9 +31,9 @@ module Axlsx
# color_scale = Axlsx::ColorScale.three_tone
# @see examples/example.rb conditional formatting examples.
def three_tone
- self.new({ type: :min, val: 0, color: 'FFF8696B' },
- { type: :percent, val: '50', color: 'FFFFEB84' },
- { type: :max, val: 0, color: 'FF63BE7B' })
+ new({ type: :min, val: 0, color: 'FFF8696B' },
+ { type: :percent, val: '50', color: 'FFFFEB84' },
+ { type: :max, val: 0, color: 'FF63BE7B' })
end
end
# A simple typed list of cfvos
diff --git a/lib/axlsx/workbook/worksheet/comment.rb b/lib/axlsx/workbook/worksheet/comment.rb
index 879e6960..4275cf8e 100644
--- a/lib/axlsx/workbook/worksheet/comment.rb
+++ b/lib/axlsx/workbook/worksheet/comment.rb
@@ -80,7 +80,7 @@ module Axlsx
# initialize the vml shape based on this comment's ref/position in the worksheet.
# by default, all columns are 5 columns wide and 5 rows high
def initialize_vml_shape
- pos = Axlsx::name_to_indices(ref)
+ pos = Axlsx.name_to_indices(ref)
@vml_shape = VmlShape.new(row: pos[1], column: pos[0], visible: @visible) do |vml|
vml.left_column = vml.column
vml.right_column = vml.column + 2
diff --git a/lib/axlsx/workbook/worksheet/comments.rb b/lib/axlsx/workbook/worksheet/comments.rb
index cb8efdaa..abf24763 100644
--- a/lib/axlsx/workbook/worksheet/comments.rb
+++ b/lib/axlsx/workbook/worksheet/comments.rb
@@ -20,7 +20,7 @@ module Axlsx
# The part name for this object
# @return [String]
def pn
- "#{COMMENT_PN % (index + 1)}"
+ format(COMMENT_PN, index + 1)
end
# Creates a new Comments object
diff --git a/lib/axlsx/workbook/worksheet/conditional_formatting.rb b/lib/axlsx/workbook/worksheet/conditional_formatting.rb
index 5f8f2474..a8ae3c36 100644
--- a/lib/axlsx/workbook/worksheet/conditional_formatting.rb
+++ b/lib/axlsx/workbook/worksheet/conditional_formatting.rb
@@ -63,7 +63,7 @@ module Axlsx
# @see rules
def rules=(v); @rules = v end
# @see sqref
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
# Serializes the conditional formatting element
# @example Conditional Formatting XML looks like:
diff --git a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
index 5d626e46..85ef886e 100644
--- a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
+++ b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
@@ -155,33 +155,33 @@ module Axlsx
end
# @see type
- def type=(v); Axlsx::validate_conditional_formatting_type(v); @type = v end
+ def type=(v); Axlsx.validate_conditional_formatting_type(v); @type = v end
# @see aboveAverage
- def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
+ def aboveAverage=(v); Axlsx.validate_boolean(v); @aboveAverage = v end
# @see bottom
- def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
+ def bottom=(v); Axlsx.validate_boolean(v); @bottom = v end
# @see dxfId
- def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
+ def dxfId=(v); Axlsx.validate_unsigned_numeric(v); @dxfId = v end
# @see equalAverage
- def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
+ def equalAverage=(v); Axlsx.validate_boolean(v); @equalAverage = v end
# @see priority
- def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
+ def priority=(v); Axlsx.validate_unsigned_numeric(v); @priority = v end
# @see operator
- def operator=(v); Axlsx::validate_conditional_formatting_operator(v); @operator = v end
+ def operator=(v); Axlsx.validate_conditional_formatting_operator(v); @operator = v end
# @see text
- def text=(v); Axlsx::validate_string(v); @text = v end
+ def text=(v); Axlsx.validate_string(v); @text = v end
# @see percent
- def percent=(v); Axlsx::validate_boolean(v); @percent = v end
+ def percent=(v); Axlsx.validate_boolean(v); @percent = v end
# @see rank
- def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
+ def rank=(v); Axlsx.validate_unsigned_numeric(v); @rank = v end
# @see stdDev
- def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
+ def stdDev=(v); Axlsx.validate_unsigned_numeric(v); @stdDev = v end
# @see stopIfTrue
- def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
+ def stopIfTrue=(v); Axlsx.validate_boolean(v); @stopIfTrue = v end
# @see timePeriod
- def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
+ def timePeriod=(v); Axlsx.validate_time_period_type(v); @timePeriod = v end
# @see formula
- def formula=(v); [*v].each { |x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
+ def formula=(v); [*v].each { |x| Axlsx.validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
# @see color_scale
def color_scale=(v)
@@ -208,7 +208,7 @@ module Axlsx
str << '<cfRule '
serialized_attributes str
str << '>'
- str << '<formula>' << [*self.formula].join('</formula><formula>') << '</formula>' if @formula
+ str << '<formula>' << [*formula].join('</formula><formula>') << '</formula>' if @formula
@color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
@data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
@icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
diff --git a/lib/axlsx/workbook/worksheet/data_bar.rb b/lib/axlsx/workbook/worksheet/data_bar.rb
index 74158d98..95e54742 100644
--- a/lib/axlsx/workbook/worksheet/data_bar.rb
+++ b/lib/axlsx/workbook/worksheet/data_bar.rb
@@ -100,7 +100,7 @@ module Axlsx
# @param [Color|String] v The color object, or rgb string value to apply
def color=(v)
@color = v if v.is_a? Color
- self.color.rgb = v if v.is_a? String
+ color.rgb = v if v.is_a? String
end
# Serialize this object to an xml string
@@ -109,7 +109,7 @@ module Axlsx
def to_xml_string(str = +'')
serialized_tag('dataBar', str) do
value_objects.to_xml_string(str)
- self.color.to_xml_string(str)
+ color.to_xml_string(str)
end
end
diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb
index bc9bc527..a84ab84d 100644
--- a/lib/axlsx/workbook/worksheet/data_validation.rb
+++ b/lib/axlsx/workbook/worksheet/data_validation.rb
@@ -178,57 +178,57 @@ module Axlsx
attr_reader :type
# @see formula1
- def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
+ def formula1=(v); Axlsx.validate_string(v); @formula1 = v end
# @see formula2
- def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
+ def formula2=(v); Axlsx.validate_string(v); @formula2 = v end
# @see allowBlank
- def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
+ def allowBlank=(v); Axlsx.validate_boolean(v); @allowBlank = v end
# @see error
- def error=(v); Axlsx::validate_string(v); @error = v end
+ def error=(v); Axlsx.validate_string(v); @error = v end
# @see errorStyle
- def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
+ def errorStyle=(v); Axlsx.validate_data_validation_error_style(v); @errorStyle = v end
# @see errorTitle
- def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
+ def errorTitle=(v); Axlsx.validate_string(v); @errorTitle = v end
# @see operator
- def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
+ def operator=(v); Axlsx.validate_data_validation_operator(v); @operator = v end
# @see prompt
- def prompt=(v); Axlsx::validate_string(v); @prompt = v end
+ def prompt=(v); Axlsx.validate_string(v); @prompt = v end
# @see promptTitle
- def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
+ def promptTitle=(v); Axlsx.validate_string(v); @promptTitle = v end
# @see showDropDown
def showDropDown=(v)
warn 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.'
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@showDropDown = v
end
# @see hideDropDown
def hideDropDown=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
# It's just an alias for the showDropDown attribute, hideDropDown should set the value of the original showDropDown.
@showDropDown = v
end
# @see showErrorMessage
- def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
+ def showErrorMessage=(v); Axlsx.validate_boolean(v); @showErrorMessage = v end
# @see showInputMessage
- def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
+ def showInputMessage=(v); Axlsx.validate_boolean(v); @showInputMessage = v end
# @see sqref
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
# @see type
- def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
+ def type=(v); Axlsx.validate_data_validation_type(v); @type = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/date_time_converter.rb b/lib/axlsx/workbook/worksheet/date_time_converter.rb
index e34ef055..01a7c21e 100644
--- a/lib/axlsx/workbook/worksheet/date_time_converter.rb
+++ b/lib/axlsx/workbook/worksheet/date_time_converter.rb
@@ -9,7 +9,7 @@ module Axlsx
# @param [Date] date the date to be serialized
# @return [Numeric]
def self.date_to_serial(date)
- epoch = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
+ epoch = Axlsx::Workbook.date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
offset_date = date.respond_to?(:utc_offset) ? date + date.utc_offset.seconds : date
(offset_date - epoch).to_f
end
@@ -23,7 +23,7 @@ module Axlsx
epoch1900 = -2209161600.0 # Time.utc(1899, 12, 30).to_i
epoch1904 = -2082844800.0 # Time.utc(1904, 1, 1).to_i
seconds_per_day = 86400.0 # 60*60*24
- epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900
+ epoch = Axlsx::Workbook.date1904 ? epoch1904 : epoch1900
(time.utc_offset + time.to_f - epoch) / seconds_per_day
end
end
diff --git a/lib/axlsx/workbook/worksheet/icon_set.rb b/lib/axlsx/workbook/worksheet/icon_set.rb
index 59d67e28..64b0c21a 100644
--- a/lib/axlsx/workbook/worksheet/icon_set.rb
+++ b/lib/axlsx/workbook/worksheet/icon_set.rb
@@ -49,7 +49,7 @@ module Axlsx
attr_reader :showValue
# @see iconSet
- def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end
+ def iconSet=(v); Axlsx.validate_icon_set(v); @iconSet = v end
# @see showValue
def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
diff --git a/lib/axlsx/workbook/worksheet/merged_cells.rb b/lib/axlsx/workbook/worksheet/merged_cells.rb
index c3fb6dde..90e1bfcb 100644
--- a/lib/axlsx/workbook/worksheet/merged_cells.rb
+++ b/lib/axlsx/workbook/worksheet/merged_cells.rb
@@ -19,7 +19,7 @@ module Axlsx
self << if cells.is_a?(String)
cells
elsif cells.is_a?(Array)
- Axlsx::cell_range(cells, false)
+ Axlsx.cell_range(cells, false)
end
end
diff --git a/lib/axlsx/workbook/worksheet/page_margins.rb b/lib/axlsx/workbook/worksheet/page_margins.rb
index 9c2ddd8e..d0a6f797 100644
--- a/lib/axlsx/workbook/worksheet/page_margins.rb
+++ b/lib/axlsx/workbook/worksheet/page_margins.rb
@@ -78,17 +78,17 @@ module Axlsx
end
# @see left
- def left=(v); Axlsx::validate_unsigned_numeric(v); @left = v end
+ def left=(v); Axlsx.validate_unsigned_numeric(v); @left = v end
# @see right
- def right=(v); Axlsx::validate_unsigned_numeric(v); @right = v end
+ def right=(v); Axlsx.validate_unsigned_numeric(v); @right = v end
# @see top
- def top=(v); Axlsx::validate_unsigned_numeric(v); @top = v end
+ def top=(v); Axlsx.validate_unsigned_numeric(v); @top = v end
# @see bottom
- def bottom=(v); Axlsx::validate_unsigned_numeric(v); @bottom = v end
+ def bottom=(v); Axlsx.validate_unsigned_numeric(v); @bottom = v end
# @see header
- def header=(v); Axlsx::validate_unsigned_numeric(v); @header = v end
+ def header=(v); Axlsx.validate_unsigned_numeric(v); @header = v end
# @see footer
- def footer=(v); Axlsx::validate_unsigned_numeric(v); @footer = v end
+ def footer=(v); Axlsx.validate_unsigned_numeric(v); @footer = v end
# Serializes the page margins element
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/page_setup.rb b/lib/axlsx/workbook/worksheet/page_setup.rb
index 6fc8ccba..ddfd698a 100644
--- a/lib/axlsx/workbook/worksheet/page_setup.rb
+++ b/lib/axlsx/workbook/worksheet/page_setup.rb
@@ -198,17 +198,17 @@ module Axlsx
end
# @see fit_to_height
- def fit_to_height=(v); Axlsx::validate_unsigned_int(v); @fit_to_height = v; end
+ def fit_to_height=(v); Axlsx.validate_unsigned_int(v); @fit_to_height = v; end
# @see fit_to_width
- def fit_to_width=(v); Axlsx::validate_unsigned_int(v); @fit_to_width = v; end
+ def fit_to_width=(v); Axlsx.validate_unsigned_int(v); @fit_to_width = v; end
# @see orientation
- def orientation=(v); Axlsx::validate_page_orientation(v); @orientation = v; end
+ def orientation=(v); Axlsx.validate_page_orientation(v); @orientation = v; end
# @see paper_height
- def paper_height=(v); Axlsx::validate_number_with_unit(v); @paper_height = v; end
+ def paper_height=(v); Axlsx.validate_number_with_unit(v); @paper_height = v; end
# @see paper_width
- def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
+ def paper_width=(v); Axlsx.validate_number_with_unit(v); @paper_width = v; end
# @see scale
- def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end
+ def scale=(v); Axlsx.validate_scale_10_400(v); @scale = v; end
# convenience method to achieve sanity when setting fit_to_width and fit_to_height
# as they both default to 1 if only their counterpart is specified.
diff --git a/lib/axlsx/workbook/worksheet/pane.rb b/lib/axlsx/workbook/worksheet/pane.rb
index 6cab87b9..91741e17 100644
--- a/lib/axlsx/workbook/worksheet/pane.rb
+++ b/lib/axlsx/workbook/worksheet/pane.rb
@@ -96,28 +96,28 @@ module Axlsx
# @see active_pane
def active_pane=(v)
- Axlsx::validate_pane_type(v)
- @active_pane = Axlsx::camel(v.to_s, false)
+ Axlsx.validate_pane_type(v)
+ @active_pane = Axlsx.camel(v.to_s, false)
end
# @see state
def state=(v)
- Axlsx::validate_split_state_type(v)
- @state = Axlsx::camel(v.to_s, false)
+ Axlsx.validate_split_state_type(v)
+ @state = Axlsx.camel(v.to_s, false)
end
# @see top_left_cell
def top_left_cell=(v)
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
- Axlsx::validate_string(cell)
+ Axlsx.validate_string(cell)
@top_left_cell = cell
end
# @see x_split
- def x_split=(v); Axlsx::validate_unsigned_int(v); @x_split = v end
+ def x_split=(v); Axlsx.validate_unsigned_int(v); @x_split = v end
# @see y_split
- def y_split=(v); Axlsx::validate_unsigned_int(v); @y_split = v end
+ def y_split=(v); Axlsx.validate_unsigned_int(v); @y_split = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb
index 97c4515b..62349288 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table.rb
@@ -159,13 +159,13 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{PIVOT_TABLE_PN % (index + 1)}"
+ format(PIVOT_TABLE_PN, index + 1)
end
# The relationship part name of this pivot table
# @return [String]
def rels_pn
- "#{PIVOT_TABLE_RELS_PN % (index + 1)}"
+ format(PIVOT_TABLE_RELS_PN, index + 1)
end
# The cache_definition for this pivot table
@@ -245,7 +245,7 @@ module Axlsx
str << "<dataFields count=\"#{data.size}\">"
data.each do |datum_value|
# The correct name prefix in ["Sum","Average", etc...]
- str << "<dataField name='#{(datum_value[:subtotal] || '')} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
+ str << "<dataField name='#{datum_value[:subtotal] || ''} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
str << " numFmtId='#{datum_value[:num_fmt]}'" if datum_value[:num_fmt]
str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal]
str << "/>"
@@ -266,7 +266,7 @@ module Axlsx
# References for header cells
# @return [Array]
def header_cell_refs
- Axlsx::range_to_a(header_range).first
+ Axlsx.range_to_a(header_range).first
end
# The header cells for the pivot table
diff --git a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
index 4928d5ac..3a6053e9 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
@@ -26,7 +26,7 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{PIVOT_TABLE_CACHE_DEFINITION_PN % (index + 1)}"
+ format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1)
end
# The identifier for this cache
diff --git a/lib/axlsx/workbook/worksheet/protected_ranges.rb b/lib/axlsx/workbook/worksheet/protected_ranges.rb
index b425d053..3e712cb5 100644
--- a/lib/axlsx/workbook/worksheet/protected_ranges.rb
+++ b/lib/axlsx/workbook/worksheet/protected_ranges.rb
@@ -19,7 +19,7 @@ module Axlsx
sqref = if cells.is_a?(String)
cells
elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
- Axlsx::cell_range(cells, false)
+ Axlsx.cell_range(cells, false)
end
self << ProtectedRange.new(sqref: sqref, name: "Range#{size}")
last
diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb
index 9f66959a..b2cd8a51 100644
--- a/lib/axlsx/workbook/worksheet/rich_text_run.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb
@@ -130,7 +130,7 @@ module Axlsx
# @see u
def u=(v)
- v = :single if (v == true || v == 1 || v == :true || v == 'true')
+ v = :single if v == true || v == 1 || v == :true || v == 'true'
set_run_style :validate_cell_u, :u, v
end
@@ -199,7 +199,7 @@ module Axlsx
return unless INLINE_STYLES.include?(attr.to_sym)
Axlsx.send(validator, value) unless validator.nil?
- self.instance_variable_set :"@#{attr}", value
+ instance_variable_set :"@#{attr}", value
end
# Serializes the RichTextRun
@@ -208,7 +208,7 @@ module Axlsx
def to_xml_string(str = +'')
valid = RichTextRun::INLINE_STYLES
data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
str << '<r><rPr>'
data.each do |key, val|
@@ -221,7 +221,7 @@ module Axlsx
str << '<' << key.to_s << ' val="' << xml_value(val) << '"/>'
end
end
- clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
+ clean_value = Axlsx.trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@value.to_s))
str << '</rPr><t>' << clean_value << '</t></r>'
end
@@ -242,7 +242,7 @@ module Axlsx
return sz if sz
font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
- (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
+ font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz
end
def style
diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb
index 0b25fc59..86d38616 100644
--- a/lib/axlsx/workbook/worksheet/row.rb
+++ b/lib/axlsx/workbook/worksheet/row.rb
@@ -129,7 +129,7 @@ module Axlsx
# @see height
def height=(v)
unless v.nil?
- Axlsx::validate_unsigned_numeric(v)
+ Axlsx.validate_unsigned_numeric(v)
@custom_height = true
@ht = v
end
diff --git a/lib/axlsx/workbook/worksheet/row_breaks.rb b/lib/axlsx/workbook/worksheet/row_breaks.rb
index 381dc0b6..98409ab4 100644
--- a/lib/axlsx/workbook/worksheet/row_breaks.rb
+++ b/lib/axlsx/workbook/worksheet/row_breaks.rb
@@ -26,7 +26,7 @@ module Axlsx
def to_xml_string(str = +'')
return if empty?
- str << '<rowBreaks count="' << self.size.to_s << '" manualBreakCount="' << self.size.to_s << '">'
+ str << '<rowBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
each { |brk| brk.to_xml_string(str) }
str << '</rowBreaks>'
end
diff --git a/lib/axlsx/workbook/worksheet/selection.rb b/lib/axlsx/workbook/worksheet/selection.rb
index 1a2633b4..3eaefeec 100644
--- a/lib/axlsx/workbook/worksheet/selection.rb
+++ b/lib/axlsx/workbook/worksheet/selection.rb
@@ -75,21 +75,21 @@ module Axlsx
# @see active_cell
def active_cell=(v)
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
- Axlsx::validate_string(cell)
+ Axlsx.validate_string(cell)
@active_cell = cell
end
# @see active_cell_id
- def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
+ def active_cell_id=(v); Axlsx.validate_unsigned_int(v); @active_cell_id = v end
# @see pane
def pane=(v)
- Axlsx::validate_pane_type(v)
- @pane = Axlsx::camel(v, false)
+ Axlsx.validate_pane_type(v)
+ @pane = Axlsx.camel(v, false)
end
# @see sqref
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb
index ce39b1b4..abf5e452 100644
--- a/lib/axlsx/workbook/worksheet/sheet_protection.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb
@@ -87,25 +87,25 @@ module Axlsx
encoded_password = encode_password(password)
password_as_hex = [encoded_password].pack("v")
- password_as_string = password_as_hex.unpack("H*").first.upcase
+ password_as_string = password_as_hex.unpack1("H*").upcase
password_as_string[2..3] + password_as_string[0..1]
end
# Encodes a given password
# Based on the algorithm provided by Daniel Rentz of OpenOffice.
- # http://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
+ # https://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
# @return [String]
def encode_password(password)
i = 0
- chars = password.split("")
+ chars = password.chars
count = chars.size
chars.collect! do |char|
i += 1
- char = char.unpack('c')[0] << i # ord << i
+ char = char.unpack1('c') << i # ord << i
low_15 = char & 0x7fff
- high_15 = char & 0x7fff << 15
+ high_15 = char & (0x7fff << 15)
high_15 = high_15 >> 15
low_15 | high_15
end
diff --git a/lib/axlsx/workbook/worksheet/sheet_view.rb b/lib/axlsx/workbook/worksheet/sheet_view.rb
index ee19061a..1ecfc7ab 100644
--- a/lib/axlsx/workbook/worksheet/sheet_view.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_view.rb
@@ -162,32 +162,32 @@ module Axlsx
end
# @see color_id
- def color_id=(v); Axlsx::validate_unsigned_int(v); @color_id = v end
+ def color_id=(v); Axlsx.validate_unsigned_int(v); @color_id = v end
# @see top_left_cell
def top_left_cell=(v)
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
- Axlsx::validate_string(cell)
+ Axlsx.validate_string(cell)
@top_left_cell = cell
end
# @see view
- def view=(v); Axlsx::validate_sheet_view_type(v); @view = v end
+ def view=(v); Axlsx.validate_sheet_view_type(v); @view = v end
# @see workbook_view_id
- def workbook_view_id=(v); Axlsx::validate_unsigned_int(v); @workbook_view_id = v end
+ def workbook_view_id=(v); Axlsx.validate_unsigned_int(v); @workbook_view_id = v end
# @see zoom_scale
- def zoom_scale=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale = v end
+ def zoom_scale=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale = v end
# @see zoom_scale_normal
- def zoom_scale_normal=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_normal = v end
+ def zoom_scale_normal=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_normal = v end
# @see zoom_scale_page_layout_view
- def zoom_scale_page_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
+ def zoom_scale_page_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
# @see zoom_scale_sheet_layout_view
- def zoom_scale_sheet_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
+ def zoom_scale_sheet_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/table.rb b/lib/axlsx/workbook/worksheet/table.rb
index 210833e0..2bfb64eb 100644
--- a/lib/axlsx/workbook/worksheet/table.rb
+++ b/lib/axlsx/workbook/worksheet/table.rb
@@ -44,7 +44,7 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{TABLE_PN % (index + 1)}"
+ format(TABLE_PN, index + 1)
end
# The relationship id for this table.
diff --git a/lib/axlsx/workbook/worksheet/table_style_info.rb b/lib/axlsx/workbook/worksheet/table_style_info.rb
index 3793d488..218e313e 100644
--- a/lib/axlsx/workbook/worksheet/table_style_info.rb
+++ b/lib/axlsx/workbook/worksheet/table_style_info.rb
@@ -34,7 +34,7 @@ module Axlsx
# explicitly be disabled or all will show.
def initialize_defaults
%w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
- self.send("#{attr}=", 0)
+ send("#{attr}=", 0)
end
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 90461c66..081f50d8 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -327,7 +327,7 @@ module Axlsx
# @param [String] name
def name=(name)
validate_sheet_name name
- @name = Axlsx::coder.encode(name)
+ @name = Axlsx.coder.encode(name)
end
# The auto filter range for the worksheet
@@ -345,13 +345,13 @@ module Axlsx
# The part name of this worksheet
# @return [String]
def pn
- "#{WORKSHEET_PN % (index + 1)}"
+ format(WORKSHEET_PN, index + 1)
end
# The relationship part name of this worksheet
# @return [String]
def rels_pn
- "#{WORKSHEET_RELS_PN % (index + 1)}"
+ format(WORKSHEET_RELS_PN, index + 1)
end
# The relationship id of this worksheet.
@@ -547,7 +547,7 @@ module Axlsx
widths.each_with_index do |value, index|
next if value.nil?
- Axlsx::validate_unsigned_numeric(value) unless value.nil?
+ Axlsx.validate_unsigned_numeric(value) unless value.nil?
find_or_create_column_info(index).width = value
end
end
@@ -584,7 +584,7 @@ module Axlsx
# @param [String|Array] cell_refs Cell references
# @param [Hash] styles
def add_style(cell_refs, *styles)
- if !cell_refs.is_a?(Array)
+ unless cell_refs.is_a?(Array)
cell_refs = [cell_refs]
end
@@ -613,7 +613,7 @@ module Axlsx
border_edges = options
end
- if !cell_refs.is_a?(Array)
+ unless cell_refs.is_a?(Array)
cell_refs = [cell_refs]
end
@@ -673,11 +673,11 @@ module Axlsx
parts.first
else
if parts.size > 2
- raise ArgumentError, (ERR_CELL_REFERENCE_INVALID % cell_def)
+ raise ArgumentError, format(ERR_CELL_REFERENCE_INVALID, cell_def)
elsif parts.first.nil?
- raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").first, cell_def])
+ raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").first, cell_def)
elsif parts.last.nil?
- raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").last, cell_def])
+ raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").last, cell_def)
end
range(*parts)
@@ -688,7 +688,7 @@ module Axlsx
# @param [String] name The cell or cell range to return. "A1" will return the first cell of the first row.
# @return [Cell]
def name_to_cell(name)
- col_index, row_index = *Axlsx::name_to_indices(name)
+ col_index, row_index = *Axlsx.name_to_indices(name)
r = rows[row_index]
@@ -711,7 +711,7 @@ module Axlsx
# @note The XLSX format does not support worksheet-specific styles. Even when using this method
# you're still working with the single global {Axlsx::Styles} object in the workbook.
def styles
- @styles ||= self.workbook.styles
+ @styles ||= workbook.styles
end
# shortcut level to specify the outline level for a series of rows
@@ -753,15 +753,15 @@ module Axlsx
def validate_sheet_name(name)
DataTypeValidator.validate :worksheet_name, String, name
# ignore first character (BOM) after encoding to utf16 because Excel does so, too.
- raise ArgumentError, (ERR_SHEET_NAME_EMPTY) if name.empty?
+ raise ArgumentError, ERR_SHEET_NAME_EMPTY if name.empty?
character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2
- raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > WORKSHEET_MAX_NAME_LENGTH
- raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if WORKSHEET_NAME_FORBIDDEN_CHARS.any? { |char| name.include? char }
+ raise ArgumentError, format(ERR_SHEET_NAME_TOO_LONG, name) if character_length > WORKSHEET_MAX_NAME_LENGTH
+ raise ArgumentError, format(ERR_SHEET_NAME_CHARACTER_FORBIDDEN, name) if WORKSHEET_NAME_FORBIDDEN_CHARS.any? { |char| name.include? char }
- name = Axlsx::coder.encode(name)
+ name = Axlsx.coder.encode(name)
sheet_names = @workbook.worksheets.reject { |s| s == self }.map(&:name)
- raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)
+ raise ArgumentError, format(ERR_DUPLICATE_SHEET_NAME, name) if sheet_names.include?(name)
end
def serializable_parts
@@ -850,7 +850,7 @@ module Axlsx
end
def add_autofilter_defined_name_to_workbook
- return if !auto_filter.range
+ return unless auto_filter.range
workbook.add_defined_name auto_filter.defined_name, name: '_xlnm._FilterDatabase', local_sheet_id: index, hidden: 1
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet_comments.rb b/lib/axlsx/workbook/worksheet/worksheet_comments.rb
index c5f5ad13..3ebaedee 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_comments.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_comments.rb
@@ -37,7 +37,7 @@ module Axlsx
# Helper method to tell us if there are comments in the comments collection
# @return [Boolean]
- def has_comments?
+ def has_comments? # rubocop:disable Naming/PredicateName
!comments.empty?
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
index 18c7189a..6488655c 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
@@ -15,8 +15,12 @@ module Axlsx
@drawing = nil
end
+ # The worksheet that owns the drawing
+ # @return [Worksheet]
attr_reader :worksheet
+ # The drawing object
+ # @return [Drawing]
attr_reader :drawing
# adds a chart to the drawing object
@@ -38,7 +42,7 @@ module Axlsx
# helper method to tell us if the drawing has something in it or not
# @return [Boolean]
- def has_drawing?
+ def has_drawing? # rubocop:disable Naming/PredicateName
@drawing.is_a? Drawing
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
index 80f7ba09..2195fc6b 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
@@ -41,7 +41,7 @@ module Axlsx
# @param [String|Cell] cell_reference The string reference or cell that defines where this hyperlink shows in the worksheet.
def ref=(cell_reference)
cell_reference = cell_reference.r if cell_reference.is_a?(Cell)
- Axlsx::validate_string cell_reference
+ Axlsx.validate_string cell_reference
@ref = cell_reference
end
@@ -69,7 +69,7 @@ module Axlsx
# r:id should only be specified for external targets.
# @return [Hash]
def location_or_id
- @target == :external ? { "r:id": relationship.Id } : { location: Axlsx::coder.encode(location) }
+ @target == :external ? { "r:id": relationship.Id } : { location: Axlsx.coder.encode(location) }
end
end
end