summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.rubocop.yml6
-rw-r--r--.rubocop_todo.yml82
-rw-r--r--CHANGELOG.md1
-rw-r--r--axlsx.gemspec12
-rw-r--r--lib/axlsx.rb8
-rw-r--r--lib/axlsx/package.rb6
-rw-r--r--lib/axlsx/util/constants.rb4
-rw-r--r--lib/axlsx/util/simple_typed_list.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/merged_cells.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/page_margins.rb9
-rwxr-xr-xtest/benchmark.rb17
11 files changed, 118 insertions, 43 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 22e574bc..a825d0cb 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -16,6 +16,9 @@ AllCops:
- 'examples/**/*'
- 'vendor/bundle/**/*'
+Gemspec:
+ Enabled: true
+
Layout:
Enabled: true
@@ -31,6 +34,9 @@ Lint:
Minitest:
Enabled: true
+Naming:
+ Enabled: true
+
Performance:
Enabled: true
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 49fda8fb..fc2954d0 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -7,6 +7,13 @@
# versions of RuboCop, may require this file to be generated again.
# This cop supports safe autocorrection (--autocorrect).
+# Configuration parameters: Severity, Include.
+# Include: **/*.gemspec
+Gemspec/RequireMFA:
+ Exclude:
+ - 'axlsx.gemspec'
+
+# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/FirstHashElementIndentation:
@@ -53,11 +60,6 @@ Lint/DisjunctiveAssignmentInConstructor:
Exclude:
- 'lib/axlsx/drawing/num_data_source.rb'
-# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
-Lint/DuplicateBranch:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/merged_cells.rb'
-
Lint/NonLocalExitFromIterator:
Exclude:
- 'lib/axlsx/util/validators.rb'
@@ -77,11 +79,67 @@ Lint/UnusedMethodArgument:
- 'lib/axlsx/package.rb'
- 'lib/axlsx/util/validators.rb'
-# Configuration parameters: MinSize.
-Performance/CollectionLiteralInLoop:
+Naming/AccessorMethodName:
Exclude:
- - 'lib/axlsx/package.rb'
- - 'lib/axlsx/workbook/worksheet/page_margins.rb'
+ - 'lib/axlsx/drawing/axes.rb'
+ - 'lib/axlsx/workbook/worksheet/data_validation.rb'
+
+# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
+# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
+# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
+Naming/FileName:
+ Exclude:
+ - 'lib/axlsx/drawing/bar_3D_chart.rb'
+ - 'lib/axlsx/drawing/line_3D_chart.rb'
+ - 'lib/axlsx/drawing/pie_3D_chart.rb'
+ - 'lib/axlsx/drawing/view_3D.rb'
+ - 'test/drawing/tc_bar_3D_chart.rb'
+ - 'test/drawing/tc_pie_3D_chart.rb'
+ - 'test/drawing/tc_view_3D.rb'
+
+# Configuration parameters: EnforcedStyle, AllowedPatterns.
+# SupportedStyles: snake_case, camelCase
+Naming/MethodName:
+ Enabled: false
+
+# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
+# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
+Naming/MethodParameterName:
+ Enabled: false
+
+# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
+# NamePrefix: is_, has_, have_
+# ForbiddenPrefixes: is_, has_, have_
+# AllowedMethods: is_a?
+# MethodDefinitionMacros: define_method, define_singleton_method
+Naming/PredicateName:
+ Exclude:
+ - 'spec/**/*'
+ - 'lib/axlsx/workbook/worksheet/cell.rb'
+ - 'lib/axlsx/workbook/worksheet/worksheet_comments.rb'
+ - 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb'
+
+# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns.
+# SupportedStyles: snake_case, camelCase
+Naming/VariableName:
+ Enabled: false
+
+# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
+# SupportedStyles: snake_case, normalcase, non_integer
+# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
+Naming/VariableNumber:
+ Exclude:
+ - 'lib/axlsx/util/validators.rb'
+ - 'lib/axlsx/workbook/worksheet/cell.rb'
+ - 'lib/axlsx/workbook/worksheet/cell_serializer.rb'
+ - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
+ - 'test/rels/tc_relationship.rb'
+ - 'test/rels/tc_relationships.rb'
+ - 'test/tc_package.rb'
+ - 'test/workbook/worksheet/tc_cell.rb'
+ - 'test/workbook/worksheet/tc_date_time_converter.rb'
+ - 'test/workbook/worksheet/tc_sheet_view.rb'
+ - 'test/workbook/worksheet/tc_worksheet.rb'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
@@ -96,12 +154,6 @@ Style/AccessorGrouping:
Style/Alias:
Enabled: false
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: MinBranchesCount.
-Style/CaseLikeIf:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/merged_cells.rb'
-
Style/ClassVars:
Exclude:
- 'lib/axlsx.rb'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf7a02ba..c7e0fc8b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ CHANGELOG
- 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
+ - Raise exception if `axlsx_styler` gem is present as its code was merged directly into `caxlsx` in v3.3.0
- **April.23.23**: 3.4.1
- [PR #209](https://github.com/caxlsx/caxlsx/pull/209) - Revert characters other than `=` being considered as formulas.
diff --git a/axlsx.gemspec b/axlsx.gemspec
index 34942176..bf9c0942 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -11,19 +11,19 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.summary = "Excel OOXML (xlsx) with charts, styles, images and autowidth columns."
s.license = 'MIT'
- s.description = <<-eof
- xlsx spreadsheet generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx helps you create beautiful Office Open XML Spreadsheet documents ( Excel, Google Spreadsheets, Numbers, LibreOffice) 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.
- eof
+ s.description = <<~MSG
+ xlsx spreadsheet generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx helps you create beautiful Office Open XML Spreadsheet documents (Excel, Google Spreadsheets, Numbers, LibreOffice) 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.
+ MSG
s.files = Dir.glob("{lib/**/*,examples/**/*.rb,examples/**/*.jpeg}") + %w{LICENSE README.md Rakefile CHANGELOG.md .yardopts .yardopts_guide}
- s.add_runtime_dependency 'nokogiri', '~> 1.10', '>= 1.10.4'
- s.add_runtime_dependency 'rubyzip', '>= 1.3.0', '< 3'
s.add_runtime_dependency "htmlentities", "~> 4.3", '>= 4.3.4'
s.add_runtime_dependency "marcel", '~> 1.0'
+ s.add_runtime_dependency 'nokogiri', '~> 1.10', '>= 1.10.4'
+ s.add_runtime_dependency 'rubyzip', '>= 1.3.0', '< 3'
- s.add_development_dependency 'yard', "~> 0.9.8"
s.add_development_dependency 'kramdown', '~> 2.3'
s.add_development_dependency 'timecop', "~> 0.9.0"
+ s.add_development_dependency 'yard', "~> 0.9.8"
s.required_ruby_version = '>= 2.6'
s.require_path = 'lib'
end
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index 58096e7c..20af45e0 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -33,12 +33,8 @@ require 'bigdecimal'
require 'set'
require 'time'
-begin
- if Gem.loaded_specs.has_key?("axlsx_styler")
- raise StandardError, "Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly."
- end
-rescue StandardError
- # Do nothing
+if Gem.loaded_specs.has_key?("axlsx_styler")
+ raise StandardError, "Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly."
end
# xlsx generation with charts, images, automated column width, customizable styles
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index 2983ed72..20195ddc 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -330,11 +330,11 @@ module Axlsx
end
exts = workbook.images.map { |image| image.extname.downcase }
exts.uniq.each do |ext|
- ct = if ['jpeg', 'jpg'].include?(ext)
+ ct = if JPEG_EXS.include?(ext)
JPEG_CT
- elsif ext == 'gif'
+ elsif ext == GIF_EX
GIF_CT
- elsif ext == 'png'
+ elsif ext == PNG_EX
PNG_CT
end
c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext)
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 138c8bf0..459e0099 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -166,8 +166,8 @@ module Axlsx
# xml content type extensions
XML_EX = "xml"
- # jpeg extension
- JPEG_EX = "jpeg"
+ # jpeg extensions
+ JPEG_EXS = ["jpeg", "jpg"].freeze
# gif extension
GIF_EX = "gif"
diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb
index c3910fca..30cfd2a5 100644
--- a/lib/axlsx/util/simple_typed_list.rb
+++ b/lib/axlsx/util/simple_typed_list.rb
@@ -15,6 +15,12 @@ module Axlsx
undef_method name
end
+ # We often call index(element) on instances of SimpleTypedList. Thus, we do not want to inherit Array
+ # implementation of == / eql? which walks the elements calling == / eql?. Instead we want the fast
+ # and original versions from BasicObject.
+ alias :== :equal?
+ alias :eql? :equal?
+
# Creats a new typed list
# @param [Array, Class] type An array of Class objects or a single Class object
# @param [String] serialize_as The tag name to use in serialization
@@ -85,12 +91,12 @@ module Axlsx
end
# join operator
- # @param [Array] v the array to join
+ # @param [Array] other the array to join
# @raise [ArgumentError] if any of the values being joined are not
# one of the allowed types
# @return [SimpleTypedList]
- def +(v)
- v.each do |item|
+ def +(other)
+ other.each do |item|
self << item
end
super
diff --git a/lib/axlsx/workbook/worksheet/merged_cells.rb b/lib/axlsx/workbook/worksheet/merged_cells.rb
index c0ca1ebe..c3fb6dde 100644
--- a/lib/axlsx/workbook/worksheet/merged_cells.rb
+++ b/lib/axlsx/workbook/worksheet/merged_cells.rb
@@ -12,7 +12,7 @@ module Axlsx
end
# adds cells to the merged cells collection
- # @param [Array||String] cells The cells to add to the merged cells
+ # @param [Array|String] cells The cells to add to the merged cells
# collection. This can be an array of actual cells or a string style
# range like 'A1:C1'
def add(cells)
@@ -20,8 +20,6 @@ module Axlsx
cells
elsif cells.is_a?(Array)
Axlsx::cell_range(cells, false)
- elsif cells.is_a?(Row)
- 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 4d133c5a..9c2ddd8e 100644
--- a/lib/axlsx/workbook/worksheet/page_margins.rb
+++ b/lib/axlsx/workbook/worksheet/page_margins.rb
@@ -29,7 +29,10 @@ module Axlsx
parse_options options
end
- serializable_attributes :left, :right, :bottom, :top, :header, :footer
+ # Possible margins to set
+ MARGIN_KEYS = [:left, :right, :top, :bottom, :header, :footer].freeze
+
+ serializable_attributes(*MARGIN_KEYS)
# Default left and right margin (in inches)
DEFAULT_LEFT_RIGHT = 0.75
@@ -65,10 +68,10 @@ module Axlsx
attr_reader :footer
# Set some or all margins at once.
- # @param [Hash] margins the margins to set (possible keys are :left, :right, :top, :bottom, :header and :footer).
+ # @param [Hash] margins the margins to set. See {MARGIN_KEYS} for a list of possible keys.
def set(margins)
margins.select do |k, v|
- next unless [:left, :right, :top, :bottom, :header, :footer].include? k
+ next unless MARGIN_KEYS.include? k
send("#{k}=", v)
end
diff --git a/test/benchmark.rb b/test/benchmark.rb
index d5ccdf64..fb4d7050 100755
--- a/test/benchmark.rb
+++ b/test/benchmark.rb
@@ -11,9 +11,22 @@ input1 = (32..126).to_a.pack('U*').chars.to_a # these will need to be escaped
input2 = (65..122).to_a.pack('U*').chars.to_a # these do not need to be escaped
10.times { row << input1.shuffle.join }
10.times { row << input2.shuffle.join }
-times = 3000
+times = 3_000
Benchmark.bmbm(30) do |x|
+ x.report('axlsx_merged_cells') do
+ p = Axlsx::Package.new
+ p.workbook do |wb|
+ wb.add_worksheet do |sheet|
+ times.times do
+ sheet << row
+ sheet.merge_cells(sheet.rows.last.cells)
+ end
+ end
+ end
+ p.serialize("example_axlsx_merged_cells.xlsx")
+ end
+
x.report('axlsx_noautowidth') do
p = Axlsx::Package.new
p.workbook do |wb|
@@ -85,4 +98,4 @@ Benchmark.bmbm(30) do |x|
end
end
end
-File.delete("example.csv", "example_streamed.xlsx", "example_shared.xlsx", "example_autowidth.xlsx", "example_noautowidth.xlsx", "example_zip_command.xlsx")
+File.delete("example_axlsx_merged_cells.xlsx", "example.csv", "example_streamed.xlsx", "example_shared.xlsx", "example_autowidth.xlsx", "example_noautowidth.xlsx", "example_zip_command.xlsx")