diff options
37 files changed, 66 insertions, 144 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b63ec71d..25b6d621 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: test_ruby_versions: runs-on: ubuntu-20.04 - continue-on-error: ${{ matrix.allow_failures || false }} + continue-on-error: ${{ matrix.allow_failures == 'allow failures' || false }} env: BUNDLE_GEMFILE: "${{ matrix.gemfile }}" ### allows adding gemfile: to the matrix, bundler will automatically pick this up @@ -26,7 +26,9 @@ jobs: - ruby: jruby-9.3 - ruby: jruby-9.4 - ruby: head - allow_failures: true + allow_failures: 'allow failures' + - ruby: jruby-head + allow_failures: 'allow failures' steps: - uses: actions/checkout@v3 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 19c4b3f5..1de00edb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -82,14 +82,6 @@ Lint/UselessAssignment: - 'lib/axlsx/workbook/worksheet/header_footer.rb' - 'lib/axlsx/workbook/worksheet/sheet_protection.rb' -# Configuration parameters: CheckForMethodsWithNoSideEffects. -Lint/Void: - Exclude: - - 'lib/axlsx/drawing/title.rb' - - 'lib/axlsx/util/storage.rb' - - 'lib/axlsx/workbook/worksheet/data_bar.rb' - - 'lib/axlsx/workbook/worksheet/pivot_table.rb' - # Configuration parameters: MinSize. Performance/CollectionLiteralInLoop: Exclude: @@ -115,13 +107,6 @@ Style/Alias: Enabled: false # This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, conditionals -Style/AndOr: - Exclude: - - 'lib/axlsx/workbook/worksheet/data_validation.rb' - -# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: MinBranchesCount. Style/CaseLikeIf: Exclude: @@ -223,13 +208,6 @@ Style/GuardClause: - 'lib/axlsx/workbook/worksheet/table.rb' - 'lib/axlsx/workbook/worksheet/worksheet.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowSplatArgument. -Style/HashConversion: - Exclude: - - 'lib/axlsx/workbook/worksheet/cell_serializer.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedReceivers. # AllowedReceivers: Thread.current @@ -244,12 +222,6 @@ Style/HashEachMethods: Style/HashSyntax: Enabled: false -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/HashTransformKeys: - Exclude: - - 'lib/axlsx/workbook/worksheet/cell_serializer.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowIfModifier. Style/IfInsideElse: @@ -336,11 +308,8 @@ Style/NonNilCheck: Style/NumericPredicate: Exclude: - 'spec/**/*' - - 'lib/axlsx/package.rb' - 'lib/axlsx/stylesheet/font.rb' - 'lib/axlsx/util/validators.rb' - - 'lib/axlsx/workbook/workbook.rb' - - 'lib/axlsx/workbook/worksheet/sheet_pr.rb' - 'lib/axlsx/workbook/worksheet/worksheet.rb' # This cop supports safe autocorrection (--autocorrect). @@ -422,26 +391,11 @@ Style/QuotedSymbols: - 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowedCompactTypes. -# SupportedStyles: compact, exploded -Style/RaiseArgs: - Exclude: - - 'lib/axlsx/package.rb' - - 'lib/axlsx/util/zip_command.rb' - - 'lib/axlsx/workbook/worksheet/border_creator.rb' - -# This cop supports safe autocorrection (--autocorrect). Style/RandomWithOffset: Exclude: - 'lib/axlsx/drawing/vml_shape.rb' # This cop supports safe autocorrection (--autocorrect). -Style/RedundantCondition: - Exclude: - - 'lib/axlsx/drawing/area_series.rb' - - 'lib/axlsx/drawing/line_series.rb' - -# This cop supports safe autocorrection (--autocorrect). Style/RedundantFileExtensionInRequire: Exclude: - 'lib/axlsx/content_type/content_type.rb' @@ -485,14 +439,6 @@ Style/RedundantRegexpEscape: - 'lib/axlsx/workbook/worksheet/table.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/axlsx/package.rb' - - 'lib/axlsx/stylesheet/styles.rb' - - 'lib/axlsx/workbook/worksheet/worksheet.rb' - -# This cop supports safe autocorrection (--autocorrect). Style/RedundantSelf: Enabled: false @@ -503,11 +449,6 @@ Style/SafeNavigation: Enabled: false # This cop supports safe autocorrection (--autocorrect). -Style/SelfAssignment: - Exclude: - - 'lib/axlsx/stylesheet/color.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowIfMethodIsEmpty. Style/SingleLineMethods: Enabled: false @@ -520,12 +461,6 @@ Style/SlicingWithRange: - 'lib/axlsx/workbook/worksheet/pivot_table.rb' - 'lib/axlsx/workbook/worksheet/worksheet.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: - Exclude: - - 'lib/axlsx/util/validators.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Style/StringChars: Exclude: @@ -608,13 +543,6 @@ Style/YodaCondition: Exclude: - 'lib/axlsx/workbook/worksheet/col.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/ZeroLengthPredicate: - Exclude: - - 'lib/axlsx/package.rb' - - 'lib/axlsx/workbook/workbook.rb' - - 'lib/axlsx/workbook/worksheet/sheet_pr.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. # URISchemes: http, https diff --git a/CHANGELOG.md b/CHANGELOG.md index 92d3396f..cf7a02ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG - Added frozen string literals - Fix `SimpleTypedList#to_a` and `SimpleTypedList#to_ary` returning the internal list instance - Remove ability to set `u=` to true in favor of using :single or one of the other underline options + - Fix `Workbook#sheet_by_name` not returning sheets with encoded characters in the name - **April.23.23**: 3.4.1 - [PR #209](https://github.com/caxlsx/caxlsx/pull/209) - Revert characters other than `=` being considered as formulas. @@ -15,7 +15,7 @@ https://github.com/caxlsx ## Synopsis Axlsx is an Office Open XML Spreadsheet generator for the Ruby programming language. -With Axlsx you can create excel worksheets with charts, images (with links), automated and fixed column widths, customized styles, functions, tables, conditional formatting, print options, comments, merged cells, auto filters, file and stream serialization as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. +With Axlsx you can create Excel worksheets with charts, images (with links), automated and fixed column widths, customized styles, functions, tables, conditional formatting, print options, comments, merged cells, auto filters, file and stream serialization as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.  diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 815e0440..58096e7c 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -143,7 +143,7 @@ module Axlsx col_ref(c_index) + row_ref(r_index) end - # Creates an array of individual cell references based on an excel reference range. + # 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) @@ -192,8 +192,8 @@ module Axlsx end # utility method for performing a deep merge on a Hash - # @param [Hash] Hash to merge into - # @param [Hash] Hash to be added + # @param [Hash] first_hash Hash to merge into + # @param [Hash] second_hash Hash to be added def self.hash_deep_merge(first_hash, second_hash) first_hash.merge(second_hash) do |_key, this_val, other_val| if this_val.is_a?(Hash) && other_val.is_a?(Hash) @@ -206,7 +206,7 @@ module Axlsx # 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. + # the workbook will be invalid and Excel will complain. def self.trust_input @trust_input ||= false end diff --git a/lib/axlsx/drawing/area_series.rb b/lib/axlsx/drawing/area_series.rb index 5cebd7da..cf4aaf13 100644 --- a/lib/axlsx/drawing/area_series.rb +++ b/lib/axlsx/drawing/area_series.rb @@ -37,7 +37,7 @@ module Axlsx # @param [Chart] chart def initialize(chart, options = {}) @show_marker = false - @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default + @marker_symbol = options[:marker_symbol] || :default @smooth = false @labels, @data = nil, nil super(chart, options) diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb index 29697378..8965599c 100644 --- a/lib/axlsx/drawing/d_lbls.rb +++ b/lib/axlsx/drawing/d_lbls.rb @@ -83,7 +83,7 @@ module Axlsx str << '</c:dLbls>' end - # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually chrash excel for any chart type other than pie charts. + # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually crash Excel for any chart type other than pie charts. def validate_attributes_for_chart_type return if [Pie3DChart, LineChart].include? @chart_type diff --git a/lib/axlsx/drawing/hyperlink.rb b/lib/axlsx/drawing/hyperlink.rb index 3fb97069..0d9eb4f7 100644 --- a/lib/axlsx/drawing/hyperlink.rb +++ b/lib/axlsx/drawing/hyperlink.rb @@ -15,7 +15,7 @@ module Axlsx # @option options [String] tgtFrame Target frame for opening hyperlink # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource. # @option options [String] href the target resource this hyperlink links to. This is actually stored on the relationship. - # @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx + # @option options [String] action A string that can be used to perform specific actions. For Excel please see this reference: https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx # @option options [Boolean] endSnd terminate any sound events when processing this link # @option options [Boolean] history include this link in the list of visited links for the applications history. # @option options [Boolean] highlightClick indicate that the link has already been visited. @@ -40,7 +40,7 @@ module Axlsx alias :invalidUrl :invalid_url alias :invalidUrl= :invalid_url= - # An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx + # An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx # @return [String] attr_accessor :action diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb index bbd3957e..fbed4000 100644 --- a/lib/axlsx/drawing/line_series.rb +++ b/lib/axlsx/drawing/line_series.rb @@ -37,7 +37,7 @@ module Axlsx # @param [Chart] chart def initialize(chart, options = {}) @show_marker = false - @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default + @marker_symbol = options[:marker_symbol] || :default @smooth = false @labels, @data = nil, nil super(chart, options) diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb index c3ca9632..2e4037fb 100644 --- a/lib/axlsx/drawing/title.rb +++ b/lib/axlsx/drawing/title.rb @@ -32,7 +32,6 @@ module Axlsx DataTypeValidator.validate 'Title.text', String, v @text = v @cell = nil - v end # @see text_size @@ -40,7 +39,6 @@ module Axlsx DataTypeValidator.validate 'Title.text_size', String, v @text_size = v @cell = nil - v end # @see cell @@ -48,7 +46,6 @@ module Axlsx DataTypeValidator.validate 'Title.text', Cell, v @cell = v @text = v.value.to_s - v end # Check if the title is empty. diff --git a/lib/axlsx/drawing/vml_drawing.rb b/lib/axlsx/drawing/vml_drawing.rb index 322ec680..364ce19a 100644 --- a/lib/axlsx/drawing/vml_drawing.rb +++ b/lib/axlsx/drawing/vml_drawing.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Axlsx - # a vml drawing used for comments in excel. + # a vml drawing used for comments in Excel. class VmlDrawing # creates a new Vml Drawing object. # @param [Comments] comments the comments object this drawing is associated with diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index b4116f76..3f225648 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -145,7 +145,7 @@ module Axlsx # Encrypt the package into a CFB using the password provided # This is not ready yet def encrypt(file_name, password) - return false + false # moc = MsOffCrypto.new(file_name, password) # moc.save end @@ -159,7 +159,7 @@ module Axlsx # # If by chance you are able to create a package that does not validate it indicates that the internal # validation is not robust enough and needs to be improved. Please report your errors to the gem author. - # @see http://www.ecma-international.org/publications/standards/Ecma-376.htm + # @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/ # @example # # The following will output any error messages found in serialization. # p = Axlsx::Package.new @@ -239,7 +239,7 @@ module Axlsx end workbook.comments.each do |comment| - if comment.size > 0 + unless comment.empty? parts << { :entry => "xl/#{comment.pn}", :doc => comment, :schema => SML_XSD } parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing, :schema => nil } end @@ -314,13 +314,13 @@ module Axlsx end workbook.comments.each do |comment| - if comment.size > 0 + unless comment.empty? c_types << Axlsx::Override.new(:PartName => "/xl/#{comment.pn}", :ContentType => COMMENT_CT) end end - if workbook.comments.size > 0 + unless workbook.comments.empty? c_types << Axlsx::Default.new(:Extension => "vml", :ContentType => VML_DRAWING_CT) end @@ -386,7 +386,7 @@ module Axlsx options.merge!(secondary_options || {}) invalid_keys = options.keys - [:confirm_valid, :zip_command] if invalid_keys.any? - raise ArgumentError.new("Invalid keyword arguments: #{invalid_keys}") + raise ArgumentError, "Invalid keyword arguments: #{invalid_keys}" end [options.fetch(:confirm_valid, false), options.fetch(:zip_command, nil)] diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb index 14d15457..93cdc88b 100644 --- a/lib/axlsx/rels/relationship.rb +++ b/lib/axlsx/rels/relationship.rb @@ -43,7 +43,7 @@ module Axlsx end # The id of the relationship (eg. "rId123"). Most instances get their own unique id. - # However, some instances need to share the same id – see {#should_use_same_id_as?} + # However, some instances need to share the same id – see {#ids_cache_key} # for details. # @return [String] attr_reader :Id diff --git a/lib/axlsx/stylesheet/cell_style.rb b/lib/axlsx/stylesheet/cell_style.rb index 5dc9a90d..5cdb4842 100644 --- a/lib/axlsx/stylesheet/cell_style.rb +++ b/lib/axlsx/stylesheet/cell_style.rb @@ -39,7 +39,7 @@ module Axlsx # @return [Integer] attr_reader :iLevel - # Determines if this named style should show in the list of styles when using excel + # Determines if this named style should show in the list of styles when using Excel # @return [Boolean] attr_reader :hidden diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb index 87308bb1..24fe3bc3 100644 --- a/lib/axlsx/stylesheet/color.rb +++ b/lib/axlsx/stylesheet/color.rb @@ -53,7 +53,7 @@ module Axlsx def rgb=(v) Axlsx::validate_string(v) v = v.upcase - v = v * 3 if v.size == 2 + v *= 3 if v.size == 2 v = v.rjust(8, 'FF') raise ArgumentError, "Invalid color rgb value: #{v}." unless /[0-9A-F]{8}/.match?(v) diff --git a/lib/axlsx/stylesheet/num_fmt.rb b/lib/axlsx/stylesheet/num_fmt.rb index 95d9a62b..4604d7bd 100644 --- a/lib/axlsx/stylesheet/num_fmt.rb +++ b/lib/axlsx/stylesheet/num_fmt.rb @@ -20,7 +20,7 @@ module Axlsx serializable_attributes :formatCode, :numFmtId # @return [String] The formatting to use for this number format. - # @see http://support.microsoft.com/kb/264372 + # @see https://support.microsoft.com/kb/264372 attr_reader :formatCode # @return [Integer] An unsigned integer referencing a standard or custom number format. diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index e8263b45..625f6a02 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -110,7 +110,7 @@ module Axlsx # @see Styles#add_style attr_reader :dxfs - # The collection of table styles that will be available to the user in the excel UI + # The collection of table styles that will be available to the user in the Excel UI # @return [SimpleTypedList] # @note The recommended way to manage styles is with add_style # @see Styles#add_style @@ -278,11 +278,9 @@ module Axlsx # Add styles to style_index cache for re-use style_index[xf_index] = raw_style - return xf_index + xf_index else - dxf_index = (dxfs << style) - - return dxf_index + dxfs << style end end @@ -457,9 +455,9 @@ module Axlsx end if options[:type] == :dxf - return border + border else - return borders << border + borders << border end end diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index 5ef3ece1..138c8bf0 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -356,7 +356,7 @@ module Axlsx # x1F Information Separator One # # The following are not dealt with. - # If you have this in your data, expect excel to blow up! + # If you have this in your data, expect Excel to blow up! # # x7F Delete # x80 Control 0080 diff --git a/lib/axlsx/util/mime_type_utils.rb b/lib/axlsx/util/mime_type_utils.rb index 5dbe0ac5..c2e6909f 100644 --- a/lib/axlsx/util/mime_type_utils.rb +++ b/lib/axlsx/util/mime_type_utils.rb @@ -16,11 +16,7 @@ module Axlsx # @param [String] v URI # @return [String] File mime type def self.get_mime_type_from_uri(v) - if URI.respond_to?(:open) - Marcel::MimeType.for(URI.open(v)) - else - Marcel::MimeType.for(URI.parse(v).open) - end + Marcel::MimeType.for(URI.open(v)) end end end diff --git a/lib/axlsx/util/storage.rb b/lib/axlsx/util/storage.rb index 2ce0d8f5..1e12b2d4 100644 --- a/lib/axlsx/util/storage.rb +++ b/lib/axlsx/util/storage.rb @@ -63,7 +63,6 @@ module Axlsx def name=(v) @name = v.bytes.to_a << 0 @name_size = @name.size * 2 - @name end # The size of the stream diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index e9cf13b6..72e3f2d8 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -55,9 +55,10 @@ module Axlsx # @return [Boolean] true if validation succeeds. # @see validate_boolean def self.validate(name, types, v, other = false) - if other.is_a?(Proc) - raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v) + if other.is_a?(Proc) && !other.call(v) + raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) end + v_class = v.is_a?(Class) ? v : v.class Array(types).each do |t| return if v_class <= t diff --git a/lib/axlsx/util/zip_command.rb b/lib/axlsx/util/zip_command.rb index e43ba03d..bc098a92 100644 --- a/lib/axlsx/util/zip_command.rb +++ b/lib/axlsx/util/zip_command.rb @@ -64,7 +64,7 @@ module Axlsx command = "cd #{escaped_dir} && #{@zip_command} #{output} #{inputs}" stdout_and_stderr, status = Open3.capture2e(command) if !status.success? - raise(ZipError.new(stdout_and_stderr)) + raise ZipError, stdout_and_stderr end end end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 1a2f0488..95d3e4a7 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -221,8 +221,8 @@ module Axlsx # @param [String] name The name of the sheet you are looking for # @return [Worksheet] The sheet found, or nil def sheet_by_name(name) - index = @worksheets.index { |sheet| sheet.name == name } - @worksheets[index] if index + encoded_name = Axlsx.coder.encode(name) + @worksheets.find { |sheet| sheet.name == encoded_name } end # Creates a new Workbook. @@ -391,7 +391,7 @@ module Axlsx end # returns a range of cells in a worksheet - # @param [String] cell_def The excel style reference defining the worksheet and cells. The range must specify the sheet to + # @param [String] cell_def The Excel style reference defining the worksheet and cells. The range must specify the sheet to # retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell. # @return [Cell, Array] def [](cell_def) @@ -406,7 +406,7 @@ module Axlsx # @param [String] str # @return [String] def to_xml_string(str = +'') - add_worksheet(name: 'Sheet1') unless worksheets.size > 0 + add_worksheet(name: 'Sheet1') if worksheets.empty? str << '<?xml version="1.0" encoding="UTF-8"?>' str << '<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">' str << '<workbookPr date1904="' << @@date1904.to_s << '"/>' diff --git a/lib/axlsx/workbook/worksheet/border_creator.rb b/lib/axlsx/workbook/worksheet/border_creator.rb index 6321916f..9abaded5 100644 --- a/lib/axlsx/workbook/worksheet/border_creator.rb +++ b/lib/axlsx/workbook/worksheet/border_creator.rb @@ -13,12 +13,12 @@ module Axlsx if @edges == :all @edges = Axlsx::Border::EDGES elsif [email protected]_a?(Array) - raise ArgumentError.new("Invalid edges provided, #{@edges}") + raise ArgumentError, "Invalid edges provided, #{@edges}" else @edges = @edges.map { |x| x&.to_sym }.uniq if !(@edges - Axlsx::Border::EDGES).empty? - raise ArgumentError.new("Invalid edges provided, #{edges}") + raise ArgumentError, "Invalid edges provided, #{edges}" end end end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 377307aa..49afa485 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -88,7 +88,7 @@ module Axlsx attr_accessor :raw_style # The index of the cellXfs item to be applied to this cell. - # @param [Hash] styles + # @param [Hash] style # @see Axlsx::Styles def add_style(style) self.raw_style ||= {} @@ -120,7 +120,7 @@ module Axlsx # automatically determed. # @see Cell#cell_type_from_value # @return [Symbol] The type of data this cell's value is cast to. - # @raise [ArgumentExeption] Cell.type must be one of [:date, time, :float, :integer, :string, :boolean] + # @raise [ArgumentError] Cell.type must be one of [:date, time, :float, :integer, :string, :boolean] # @note # If the value provided cannot be cast into the type specified, type is changed to :string and the following logic is applied. # :string to :integer or :float, type conversions always return 0 or 0.0 diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb index c9bee5b0..30a2b5fe 100644 --- a/lib/axlsx/workbook/worksheet/cell_serializer.rb +++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb @@ -26,7 +26,7 @@ module Axlsx def run_xml_string(cell, str = +'') if cell.is_text_run? valid = RichTextRun::INLINE_STYLES - [:value, :type] - data = Hash[Axlsx.instance_values_for(cell).map { |k, v| [k.to_sym, v] }] + data = Axlsx.instance_values_for(cell).transform_keys(&:to_sym) data = data.select { |key, value| valid.include?(key) && !value.nil? } RichText.new(cell.value.to_s, data).to_xml_string(str) elsif cell.contains_rich_text? diff --git a/lib/axlsx/workbook/worksheet/data_bar.rb b/lib/axlsx/workbook/worksheet/data_bar.rb index 108a5c16..482bd029 100644 --- a/lib/axlsx/workbook/worksheet/data_bar.rb +++ b/lib/axlsx/workbook/worksheet/data_bar.rb @@ -101,7 +101,6 @@ module Axlsx def color=(v) @color = v if v.is_a? Color self.color.rgb = v if v.is_a? String - @color end # Serialize this object to an xml string diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb index eca90743..bc9bc527 100644 --- a/lib/axlsx/workbook/worksheet/data_validation.rb +++ b/lib/axlsx/workbook/worksheet/data_validation.rb @@ -243,8 +243,8 @@ module Axlsx str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"' end str << '>' - str << '<formula1>' << self.formula1 << '</formula1>' if @formula1 and valid_attributes.include?(:formula1) - str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2) + str << '<formula1>' << formula1 << '</formula1>' if formula1 && valid_attributes.include?(:formula1) + str << '<formula2>' << formula2 << '</formula2>' if formula2 && valid_attributes.include?(:formula2) str << '</dataValidation>' end diff --git a/lib/axlsx/workbook/worksheet/date_time_converter.rb b/lib/axlsx/workbook/worksheet/date_time_converter.rb index ffa2831a..e34ef055 100644 --- a/lib/axlsx/workbook/worksheet/date_time_converter.rb +++ b/lib/axlsx/workbook/worksheet/date_time_converter.rb @@ -3,9 +3,9 @@ require "date" module Axlsx - # The DateTimeConverter class converts both data and time types to their apprpriate excel serializations + # The DateTimeConverter class converts both data and time types to their apprpriate Excel serializations class DateTimeConverter - # The date_to_serial method converts Date objects to the equivelant excel serialized forms + # The date_to_serial method converts Date objects to the equivelant Excel serialized forms # @param [Date] date the date to be serialized # @return [Numeric] def self.date_to_serial(date) @@ -14,7 +14,7 @@ module Axlsx (offset_date - epoch).to_f end - # The time_to_serial methond converts a Time object its excel serialized form. + # The time_to_serial methond converts a Time object its Excel serialized form. # @param [Time] time the time to be serialized # @return [Numeric] def self.time_to_serial(time) diff --git a/lib/axlsx/workbook/worksheet/header_footer.rb b/lib/axlsx/workbook/worksheet/header_footer.rb index c60d6678..0b86212d 100644 --- a/lib/axlsx/workbook/worksheet/header_footer.rb +++ b/lib/axlsx/workbook/worksheet/header_footer.rb @@ -45,7 +45,7 @@ module Axlsx def to_xml_string(str = +'') serialized_tag('headerFooter', str) do serialized_element_attributes(str) do |value| - value = ::CGI.escapeHTML(value) + ::CGI.escapeHTML(value) end end end diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index 27065e4b..44a50f19 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -135,7 +135,6 @@ module Axlsx end @data << data_field end - @data end # The pages diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index 883d01d3..ffd2f941 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -207,7 +207,7 @@ module Axlsx # @return [String] def to_xml_string(str = +'') valid = RichTextRun::INLINE_STYLES - data = Hash[Axlsx.instance_values_for(self).map { |k, v| [k.to_sym, v] }] + data = Axlsx.instance_values_for(self).transform_keys(&:to_sym) data = data.select { |key, value| valid.include?(key) && !value.nil? } str << '<r><rPr>' diff --git a/lib/axlsx/workbook/worksheet/row_breaks.rb b/lib/axlsx/workbook/worksheet/row_breaks.rb index 56e8c4c6..21691f7a 100644 --- a/lib/axlsx/workbook/worksheet/row_breaks.rb +++ b/lib/axlsx/workbook/worksheet/row_breaks.rb @@ -13,7 +13,7 @@ module Axlsx # max and man values are fixed. # @see Break def add_break(options) - # force feed the excel default + # force feed the Excel default self << Break.new(options.merge(:max => 16383, :man => true)) last end diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb index 86826f77..ea191fa0 100644 --- a/lib/axlsx/workbook/worksheet/sheet_pr.rb +++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb @@ -82,7 +82,7 @@ module Axlsx def update_properties page_setup_pr.fit_to_page = worksheet.fit_to_page? - if worksheet.auto_filter.columns.size > 0 + unless worksheet.auto_filter.columns.empty? self.filter_mode = 1 self.enable_format_conditions_calculation = 1 end diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb index e506f8d9..ce39b1b4 100644 --- a/lib/axlsx/workbook/worksheet/sheet_protection.rb +++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb @@ -107,7 +107,7 @@ module Axlsx low_15 = char & 0x7fff high_15 = char & 0x7fff << 15 high_15 = high_15 >> 15 - char = low_15 | high_15 + low_15 | high_15 end encoded_password = 0x0000 diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 21c53409..8c6e53b4 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -65,7 +65,7 @@ module Axlsx # Specifies the visible state of this sheet. Allowed states are # :visible, :hidden or :very_hidden. The default value is :visible. # - # Worksheets in the :hidden state can be shown using the sheet formatting properties in excel. + # Worksheets in the :hidden state can be shown using the sheet formatting properties in Excel. # :very_hidden sheets should be inaccessible to end users. # @param [Symbol] sheet_state The visible state for this sheet. def state=(sheet_state) @@ -173,7 +173,7 @@ module Axlsx @rows.transpose(&block) end - # A range that excel will apply an auto-filter to "A1:B3" + # A range that Excel will apply an auto-filter to "A1:B3" # This will turn filtering on for the cells in the range. # The first row is considered the header, while subsequent rows are considered to be data. # @return String @@ -519,7 +519,7 @@ module Axlsx end # Adds a page break (row break) to the worksheet - # @param cell A Cell object or excel style string reference indicating where the break + # @param cell A Cell object or Excel style string reference indicating where the break # should be added to the sheet. # @example # ws.add_page_break("A4") @@ -581,7 +581,7 @@ module Axlsx end # Set the style for cells in a specific column - # @param [String|Array] cell references + # @param [String|Array] cell_refs Cell references # @param [Hash] styles def add_style(cell_refs, *styles) if !cell_refs.is_a?(Array) @@ -602,8 +602,8 @@ module Axlsx end # Set the style for cells in a specific column - # @param [String|Array] cell references - # @param [Hash|Array|Symbol] border options + # @param [String|Array] cell_refs Cell references + # @param [Hash|Array|Symbol] options border options def add_border(cell_refs, options = nil) if options.is_a?(Hash) border_edges = options[:edges] @@ -661,7 +661,7 @@ module Axlsx r end - # Returns the cell or cells defined using excel style A1:B3 references. + # Returns the cell or cells defined using Excel style A1:B3 references. # @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber # @return [Cell, Array] def [](cell_def) @@ -693,7 +693,7 @@ module Axlsx r = rows[row_index] if r - return r[col_index] + r[col_index] end end diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb index d85c17d9..b1cfdc71 100644 --- a/test/workbook/tc_workbook.rb +++ b/test/workbook/tc_workbook.rb @@ -47,8 +47,10 @@ class TestWorkbook < Test::Unit::TestCase def test_sheet_by_name_retrieval @wb.add_worksheet(:name => 'foo') @wb.add_worksheet(:name => 'bar') + @wb.add_worksheet(:name => "testin'") assert_equal('foo', @wb.sheet_by_name('foo').name) + assert_equal("testin'", @wb.sheet_by_name("testin'").name) end def test_worksheet_empty_name |
