From be7d4741df5fa254db7f04195a25a0604795ef49 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Sun, 8 Sep 2019 19:25:38 -0700 Subject: [PATCH 01/42] Add community caxlsx notice --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 68a78a64..e31f5728 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +Notice: Community Axlsx organization +=================================================== +All Axlsx related gems have been forked or moved to a community organization: http://github.com/caxlsx +* Axlsx +* acts_as_axlsx +* axlsx_rails + +Please consider helping develop and test these gems. + Axlsx: Office Open XML Spreadsheet Generation ==================================== [![Build Status](https://secure.travis-ci.org/randym/axlsx.svg?branch=master)](http://travis-ci.org/randym/axlsx/) From 3345543823a64d523c3866664b14f71cb389d27c Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Sun, 8 Sep 2019 19:30:22 -0700 Subject: [PATCH 02/42] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e31f5728..623b876a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ All Axlsx related gems have been forked or moved to a community organization: ht * acts_as_axlsx * axlsx_rails +The gems will be released as is as a starting point to allow releases of other gems that depend on these gems. Submit issues as usual. + Please consider helping develop and test these gems. Axlsx: Office Open XML Spreadsheet Generation From e9b2db709066746ba5ff9073015de76bf3fc9c0e Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Sun, 8 Sep 2019 19:36:26 -0700 Subject: [PATCH 03/42] Update README.md --- README.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 623b876a..2aab3264 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ All Axlsx related gems have been forked or moved to a community organization: ht * Axlsx * acts_as_axlsx * axlsx_rails +* activeadmin-axlsx The gems will be released as is as a starting point to allow releases of other gems that depend on these gems. Submit issues as usual. @@ -18,9 +19,7 @@ appreciation for the gem, please don't hesitate to make a donation. **IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx) -**Git**:[http://github.com/randym/axlsx](http://github.com/randym/axlsx) - -**Twitter**: [https://twitter.com/morgan_randy](https://twitter.com/morgan_randy) +**Git**:[http://github.com/caxlsx/axlsx](http://github.com/randym/axlsx) **Google Group**: [https://groups.google.com/forum/?fromgroups#!forum/axlsx](https://groups.google.com/forum/?fromgroups#!forum/axlsx) @@ -41,7 +40,7 @@ appreciation for the gem, please don't hesitate to make a donation. **Release Date**: September 12th 2013 If you are working in rails, or with active record see: -[acts_as_xlsx](http://github.com/randym/acts_as_xlsx) +[acts_as_xlsx](http://github.com/caxlsx/acts_as_xlsx) acts_as_xlsx is a simple ActiveRecord mixin that lets you generate a workbook with: @@ -51,7 +50,7 @@ Posts.where(created_at > Time.now-30.days).to_xlsx ** and ** -* http://github.com/straydogstudio/axlsx_rails +* http://github.com/caxlsx/axlsx_rails Axlsx_Rails provides an Axlsx renderer so you can move all your spreadsheet code from your controller into view files. Partials are supported so you can organize any code into reusable chunks (e.g. cover sheets, common styling, etc.) You can use it with acts_as_xlsx, placing the to_xlsx call in a view and add ':package => xlsx_package' to the parameter list. Now you can keep your controllers thin! There are guides for using axlsx and acts_as_xlsx here: @@ -59,7 +58,7 @@ There are guides for using axlsx and acts_as_xlsx here: If you are working with ActiveAdmin see: -[activeadmin-axlsx](http://github.com/randym/activeadmin-axlsx) +[activeadmin-axlsx](http://github.com/caxlsx/activeadmin-axlsx) It provides a plugin and dsl for generating downloadable reports. @@ -72,7 +71,7 @@ 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. -![Screen 1](https://github.com/randym/axlsx/raw/master/examples/sample.png) +![Screen 1](https://github.com/caxlsx/axlsx/raw/master/examples/sample.png) @@ -151,7 +150,7 @@ Axlsx::Package.new do |p| end ``` -Please see the [examples](https://github.com/randym/axlsx/tree/master/examples/example.rb) for more. +Please see the [examples](https://github.com/caxlsx/axlsx/tree/master/examples/example.rb) for more. {include:file:examples/example.rb} @@ -257,11 +256,9 @@ related to themes, which axlsx does not implement at this time. Open source software is a community effort. None of this could have been done without the help of these awesome folks. -[contributors](https://github.com/randym/axlsx/graphs/contributors) +[contributors](https://github.com/caxlsx/axlsx/graphs/contributors) -#Copyright and License +#License ---------- -Axlsx © 2011-2013 by [Randy Morgan](mailto:digial.ipseity@gmail.com). - Axlsx is licensed under the MIT license. Please see the LICENSE document for more information. From 51f4e4fc7c0c2b661b84d892ca8a93e28996b95f Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Sun, 8 Sep 2019 19:49:08 -0700 Subject: [PATCH 04/42] Release 3.0.0 --- lib/axlsx/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index 10f78875..22a02aa2 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -1,5 +1,5 @@ module Axlsx # The current version - VERSION = "3.0.0.pre" + VERSION = "3.0.0" end From 9c194405b57c803c65943f7cdce2fb825bd892e7 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Sun, 8 Sep 2019 21:07:05 -0700 Subject: [PATCH 05/42] Change gem name --- axlsx.gemspec | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/axlsx.gemspec b/axlsx.gemspec index d1a25429..1de84ca7 100644 --- a/axlsx.gemspec +++ b/axlsx.gemspec @@ -1,15 +1,14 @@ require File.expand_path('../lib/axlsx/version', __FILE__) Gem::Specification.new do |s| - s.name = 'axlsx' + s.name = 'caxlsx' s.version = Axlsx::VERSION - s.authors = ["Randy Morgan", "Jurriaan Pruis"] - s.email = 'digital.ipseity@gmail.com' - s.homepage = 'https://github.com/randym/axlsx' + s.authors = ["Randy Morgan", "Jurriaan Pruis", "Noel Peden"] + s.email = 'noel@peden.biz' + s.homepage = 'https://github.com/caxlsx/axlsx' s.platform = Gem::Platform::RUBY s.date = Time.now.strftime('%Y-%m-%d') s.summary = "Excel OOXML (xlsx) with charts, styles, images and autowidth columns." - s.has_rdoc = 'axlsx' 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. From 7e13f96274f885708f9abe564f1e4a362b93bca0 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Tue, 10 Sep 2019 08:24:57 -0700 Subject: [PATCH 06/42] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 2aab3264..b9fec11f 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ All Axlsx related gems have been forked or moved to a community organization: ht * axlsx_rails * activeadmin-axlsx -The gems will be released as is as a starting point to allow releases of other gems that depend on these gems. Submit issues as usual. - Please consider helping develop and test these gems. Axlsx: Office Open XML Spreadsheet Generation From b63a8019c213a64e1f08f0b8d120a7a24dfc3f0c Mon Sep 17 00:00:00 2001 From: Koza Date: Tue, 17 Sep 2019 11:23:54 +0200 Subject: [PATCH 07/42] Add caxlsx.rb to make auto require work https://guides.rubygems.org/make-your-own-gem/ The convention is to have one Ruby file with the same name as your gem, since that gets loaded when require is run. --- lib/caxlsx.rb | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 lib/caxlsx.rb diff --git a/lib/caxlsx.rb b/lib/caxlsx.rb new file mode 100644 index 00000000..a82d49fb --- /dev/null +++ b/lib/caxlsx.rb @@ -0,0 +1,2 @@ +# encoding: UTF-8 +require 'axlsx.rb' From 08314a9d4e47604a9b39999475fe193354c73618 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Mon, 23 Sep 2019 22:17:07 -0700 Subject: [PATCH 08/42] Gemspec home page fix [skip ci] --- axlsx.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axlsx.gemspec b/axlsx.gemspec index 1de84ca7..ae656429 100644 --- a/axlsx.gemspec +++ b/axlsx.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.version = Axlsx::VERSION s.authors = ["Randy Morgan", "Jurriaan Pruis", "Noel Peden"] s.email = 'noel@peden.biz' - s.homepage = 'https://github.com/caxlsx/axlsx' + s.homepage = 'https://github.com/caxlsx/caxlsx' s.platform = Gem::Platform::RUBY s.date = Time.now.strftime('%Y-%m-%d') s.summary = "Excel OOXML (xlsx) with charts, styles, images and autowidth columns." From e383a600309bee5ee82259d7904b0ba3bfa49058 Mon Sep 17 00:00:00 2001 From: Paul McMahon Date: Thu, 26 Sep 2019 17:23:04 +0900 Subject: [PATCH 09/42] Fix URL in README (#6) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9fec11f..1472f09d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ appreciation for the gem, please don't hesitate to make a donation. **IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx) -**Git**:[http://github.com/caxlsx/axlsx](http://github.com/randym/axlsx) +**Git**:[http://github.com/caxlsx/axlsx](http://github.com/caxlsx/axlsx) **Google Group**: [https://groups.google.com/forum/?fromgroups#!forum/axlsx](https://groups.google.com/forum/?fromgroups#!forum/axlsx) From 896b95b7e4a5c48bf27390eab1ecffa2f11346e7 Mon Sep 17 00:00:00 2001 From: takkanm Date: Thu, 19 Sep 2019 06:09:58 +0900 Subject: [PATCH 10/42] add and update some ruby versions --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e7627047..d37ee3ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,11 @@ notifications: matrix: include: - rvm: 2.1 - - rvm: 2.2.8 + - rvm: 2.2.10 - rvm: 2.3.5 - - rvm: 2.4.2 + - rvm: 2.4.7 + - rvm: 2.5.6 + - rvm: 2.6.4 - rvm: rbx-3 - rvm: jruby-19mode - rvm: jruby-9.1.17.0 From e80ac9b9d6774ac8d2d9cafc8551b93b0d4ef9ed Mon Sep 17 00:00:00 2001 From: takkanm Date: Thu, 19 Sep 2019 06:10:08 +0900 Subject: [PATCH 11/42] add some ruby versions --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 0d7d5fce..c2fd1547 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,9 @@ version: 2.1.0.{build}-{branch} environment: matrix: + - RUBY_VERSION: 26 + - RUBY_VERSION: 25 + - RUBY_VERSION: 24 - RUBY_VERSION: 23 - RUBY_VERSION: 22 - RUBY_VERSION: 21 From 775b260770da7d80635d72e02b187f2cba7868a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Thu, 12 Sep 2019 12:50:35 +0200 Subject: [PATCH 12/42] Update README.md to show Travis CI status of this fork. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1472f09d..1e3fbc09 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Please consider helping develop and test these gems. Axlsx: Office Open XML Spreadsheet Generation ==================================== -[![Build Status](https://secure.travis-ci.org/randym/axlsx.svg?branch=master)](http://travis-ci.org/randym/axlsx/) +[![Build Status](https://travis-ci.com/caxlsx/caxlsx.svg?branch=master)](https://travis-ci.com/caxlsx/caxlsx) If you are using axlsx for commercial purposes, or just want to show your appreciation for the gem, please don't hesitate to make a donation. From 955f1307d310badc88a458ed9428ed569014be4f Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Thu, 26 Sep 2019 10:41:24 +0200 Subject: [PATCH 13/42] Update gem install instructions to use caxlsx --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e3fbc09..f57506c9 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Installing To install Axlsx, use the following command: - $ gem install axlsx + $ gem install caxlsx #Examples ------ From acf116e7d00850fb91380ce01fa43d6a67dbd494 Mon Sep 17 00:00:00 2001 From: Josh Goodall Date: Wed, 11 Sep 2019 09:06:20 +1000 Subject: [PATCH 14/42] Bump dependencies for nokogiri, rubyzip, and Ruby. nokogiri <1.10.4 and rubyzip < 1.3.0 had CVEs and/or regressions, and whilst we're here, signal that it's okay to use Ruby 2.3 syntax and methods and later. --- axlsx.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/axlsx.gemspec b/axlsx.gemspec index 1de84ca7..bfdf0f9b 100644 --- a/axlsx.gemspec +++ b/axlsx.gemspec @@ -16,14 +16,14 @@ Gem::Specification.new do |s| s.files = Dir.glob("{lib/**/*,examples/**/*.rb,examples/**/*.jpeg}") + %w{ LICENSE README.md Rakefile CHANGELOG.md .yardopts .yardopts_guide } s.test_files = Dir.glob("{test/**/*}") - s.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.2' - s.add_runtime_dependency 'rubyzip','~> 1.2', '>= 1.2.1' + 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 "mimemagic", '~> 0.3' s.add_development_dependency 'yard', "~> 0.9.8" s.add_development_dependency 'kramdown', '~> 1.16', '>= 1.16.2' s.add_development_dependency 'timecop', "~> 0.8.1" - s.required_ruby_version = '>= 1.9.2' + s.required_ruby_version = '~> 2.3' s.require_path = 'lib' end From c73b36d80f6a07862ead30a593f62b4797926110 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Mon, 30 Sep 2019 22:44:53 -0700 Subject: [PATCH 15/42] Fix github links / repo names [skip ci] --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f57506c9..114c2bed 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ appreciation for the gem, please don't hesitate to make a donation. **IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx) -**Git**:[http://github.com/caxlsx/axlsx](http://github.com/caxlsx/axlsx) +**Git**:[http://github.com/caxlsx/caxlsx](http://github.com/caxlsx/caxlsx) **Google Group**: [https://groups.google.com/forum/?fromgroups#!forum/axlsx](https://groups.google.com/forum/?fromgroups#!forum/axlsx) @@ -38,9 +38,9 @@ appreciation for the gem, please don't hesitate to make a donation. **Release Date**: September 12th 2013 If you are working in rails, or with active record see: -[acts_as_xlsx](http://github.com/caxlsx/acts_as_xlsx) +[acts_as_caxlsx](http://github.com/caxlsx/acts_as_caxlsx) -acts_as_xlsx is a simple ActiveRecord mixin that lets you generate a workbook with: +acts_as_caxlsx is a simple ActiveRecord mixin that lets you generate a workbook with: ```ruby Posts.where(created_at > Time.now-30.days).to_xlsx @@ -56,7 +56,7 @@ There are guides for using axlsx and acts_as_xlsx here: If you are working with ActiveAdmin see: -[activeadmin-axlsx](http://github.com/caxlsx/activeadmin-axlsx) +[activeadmin-caxlsx](http://github.com/caxlsx/activeadmin-caxlsx) It provides a plugin and dsl for generating downloadable reports. From 913003eaf0456e4645cad91f2622354deae10841 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Wed, 3 Aug 2016 12:09:19 +0300 Subject: [PATCH 16/42] Fix Relationship.instances cache. This PR aims to fix several issues with Relationship cache: 1) It's not threadsafe, so I propose to use a TLS variable for this. 2) Memory obtained by cache remains non-freed before the next run of `serialize`. I think it should be freed immediately. 3) Memory should be freed in `ensure` block to prevent memory bloating in case of exception. *There are only two hard things in Computer Science: cache invalidation and naming things.* --- lib/axlsx/package.rb | 8 ++++++-- lib/axlsx/rels/relationship.rb | 18 +++++++++++++----- test/rels/tc_relationship.rb | 8 ++++++++ test/tc_package.rb | 2 ++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index da661b34..2e9e14fc 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -100,11 +100,13 @@ def workbook=(workbook) DataTypeValidator.validate :Package_workbook, Workbook, # File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) } def serialize(output, confirm_valid=false) return false unless !confirm_valid || self.validate.empty? - Relationship.clear_cached_instances + Relationship.initialize_cached_instances Zip::OutputStream.open(output) do |zip| write_parts(zip) end true + ensure + Relationship.clear_cached_instances end @@ -113,11 +115,13 @@ def serialize(output, confirm_valid=false) # @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not. def to_stream(confirm_valid=false) return false unless !confirm_valid || self.validate.empty? - Relationship.clear_cached_instances + Relationship.initialize_cached_instances zip = write_parts(Zip::OutputStream.new(StringIO.new, true)) stream = zip.close_buffer stream.rewind stream + ensure + Relationship.clear_cached_instances end # Encrypt the package into a CFB using the password provided diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb index 99dad367..66f53b2a 100644 --- a/lib/axlsx/rels/relationship.rb +++ b/lib/axlsx/rels/relationship.rb @@ -8,20 +8,28 @@ class << self # Keeps track of all instances of this class. # @return [Array] def instances - @instances ||= [] + Thread.current[:axlsx_relationship_cached_instances] ||= [] end - - # Clear cached instances. + + # Initialize cached instances. # # This should be called before serializing a package (see {Package#serialize} and # {Package#to_stream}) to make sure that serialization is idempotent (i.e. # Relationship instances are generated with the same IDs everytime the package # is serialized). + def initialize_cached_instances + Thread.current[:axlsx_relationship_cached_instances] = [] + end + + # Clear cached instances. + # + # This should be called after serializing a package (see {Package#serialize} and + # {Package#to_stream}) to free the memory allocated for cache. # # Also, calling this avoids memory leaks (cached instances lingering around # forever). def clear_cached_instances - @instances = [] + Thread.current[:axlsx_relationship_cached_instances] = nil end # Generate and return a unique id (eg. `rId123`) Used for setting {#Id}. @@ -30,7 +38,7 @@ def clear_cached_instances # {clear_cached_instances} will automatically reset the generated ids, too. # @return [String] def next_free_id - "rId#{@instances.size + 1}" + "rId#{instances.size + 1}" end end diff --git a/test/rels/tc_relationship.rb b/test/rels/tc_relationship.rb index add1654f..845f789e 100644 --- a/test/rels/tc_relationship.rb +++ b/test/rels/tc_relationship.rb @@ -13,6 +13,14 @@ def test_instances_with_same_attributes_share_id instance = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target') assert_equal instance.Id, Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target').Id end + + def test_instances_cache_is_thread_safe + cache1, cache2 = nil + t1 = Thread.new { cache1 = Axlsx::Relationship.instances } + t2 = Thread.new { cache2 = Axlsx::Relationship.instances } + [t1, t2].each(&:join) + assert_not_same(cache1, cache2) + end def test_target_is_only_considered_for_same_attributes_check_if_target_mode_is_external source_obj = Object.new diff --git a/test/tc_package.rb b/test/tc_package.rb index d89f35b0..4bd0d429 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -236,6 +236,8 @@ def test_to_stream # this is just a roundabout guess for a package as it is build now # in testing. assert(stream.size > 80000) + # Cached instances should be cleared + assert(Axlsx::Relationship.instances.empty?) end def test_encrypt From 09469669ccadf8580643eae8352372e92e1ddbb0 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Sat, 9 Mar 2019 19:49:27 +0300 Subject: [PATCH 17/42] Cache relationship in Hash rather than in Array. Also cacle only ids, not entire instances. --- lib/axlsx/package.rb | 8 +++--- lib/axlsx/rels/relationship.rb | 47 +++++++++++++++------------------- test/rels/tc_relationship.rb | 6 ++--- test/tc_package.rb | 4 +-- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 2e9e14fc..56410339 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -100,13 +100,13 @@ def workbook=(workbook) DataTypeValidator.validate :Package_workbook, Workbook, # File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) } def serialize(output, confirm_valid=false) return false unless !confirm_valid || self.validate.empty? - Relationship.initialize_cached_instances + Relationship.initialize_ids_cache Zip::OutputStream.open(output) do |zip| write_parts(zip) end true ensure - Relationship.clear_cached_instances + Relationship.clear_ids_cache end @@ -115,13 +115,13 @@ def serialize(output, confirm_valid=false) # @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not. def to_stream(confirm_valid=false) return false unless !confirm_valid || self.validate.empty? - Relationship.initialize_cached_instances + Relationship.initialize_ids_cache zip = write_parts(Zip::OutputStream.new(StringIO.new, true)) stream = zip.close_buffer stream.rewind stream ensure - Relationship.clear_cached_instances + Relationship.clear_ids_cache end # Encrypt the package into a CFB using the password provided diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb index 66f53b2a..ad47c9a3 100644 --- a/lib/axlsx/rels/relationship.rb +++ b/lib/axlsx/rels/relationship.rb @@ -5,40 +5,40 @@ module Axlsx class Relationship class << self - # Keeps track of all instances of this class. + # Keeps track of relationship ids in use. # @return [Array] - def instances - Thread.current[:axlsx_relationship_cached_instances] ||= [] + def ids_cache + Thread.current[:axlsx_relationship_ids_cache] ||= {} end - # Initialize cached instances. + # Initialize cached ids. # # This should be called before serializing a package (see {Package#serialize} and # {Package#to_stream}) to make sure that serialization is idempotent (i.e. # Relationship instances are generated with the same IDs everytime the package # is serialized). - def initialize_cached_instances - Thread.current[:axlsx_relationship_cached_instances] = [] + def initialize_ids_cache + Thread.current[:axlsx_relationship_ids_cache] = {} end - # Clear cached instances. + # Clear cached ids. # # This should be called after serializing a package (see {Package#serialize} and # {Package#to_stream}) to free the memory allocated for cache. # - # Also, calling this avoids memory leaks (cached instances lingering around + # Also, calling this avoids memory leaks (cached ids lingering around # forever). - def clear_cached_instances - Thread.current[:axlsx_relationship_cached_instances] = nil + def clear_ids_cache + Thread.current[:axlsx_relationship_ids_cache] = nil end # Generate and return a unique id (eg. `rId123`) Used for setting {#Id}. # - # The generated id depends on the number of cached instances, so using - # {clear_cached_instances} will automatically reset the generated ids, too. + # The generated id depends on the number of previously cached ids, so using + # {clear_ids_cache} will automatically reset the generated ids, too. # @return [String] def next_free_id - "rId#{instances.size + 1}" + "rId#{ids_cache.size + 1}" end end @@ -88,12 +88,7 @@ def initialize(source_obj, type, target, options={}) self.Target=target self.Type=type self.TargetMode = options[:target_mode] if options[:target_mode] - @Id = if (existing = self.class.instances.find{ |i| should_use_same_id_as?(i) }) - existing.Id - else - self.class.next_free_id - end - self.class.instances << self + @Id = (self.class.ids_cache[ids_cache_key] ||= self.class.next_free_id) end # @see Target @@ -114,7 +109,7 @@ def to_xml_string(str = '') str << '/>' end - # Whether this relationship should use the same id as `other`. + # A key that determines whether this relationship should use already generated id. # # Instances designating the same relationship need to use the same id. We can not simply # compare the {#Target} attribute, though: `foo/bar.xml`, `../foo/bar.xml`, @@ -124,13 +119,11 @@ def to_xml_string(str = '') # then {#Target} will be an absolute URL and thus can safely be compared). # # @todo Implement comparison of {#Target} based on normalized path names. - # @param other [Relationship] - def should_use_same_id_as?(other) - result = self.source_obj == other.source_obj && self.Type == other.Type && self.TargetMode == other.TargetMode - if self.TargetMode == :External - result &&= self.Target == other.Target - end - result + # @return [Array] + def ids_cache_key + key = [source_obj, self.Type, self.TargetMode] + key << self.Target if self.TargetMode == :External + key end end diff --git a/test/rels/tc_relationship.rb b/test/rels/tc_relationship.rb index 845f789e..f47b6a4d 100644 --- a/test/rels/tc_relationship.rb +++ b/test/rels/tc_relationship.rb @@ -14,10 +14,10 @@ def test_instances_with_same_attributes_share_id assert_equal instance.Id, Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target').Id end - def test_instances_cache_is_thread_safe + def test_ids_cache_is_thread_safe cache1, cache2 = nil - t1 = Thread.new { cache1 = Axlsx::Relationship.instances } - t2 = Thread.new { cache2 = Axlsx::Relationship.instances } + t1 = Thread.new { cache1 = Axlsx::Relationship.ids_cache } + t2 = Thread.new { cache2 = Axlsx::Relationship.ids_cache } [t1, t2].each(&:join) assert_not_same(cache1, cache2) end diff --git a/test/tc_package.rb b/test/tc_package.rb index 4bd0d429..1e5ce322 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -236,8 +236,8 @@ def test_to_stream # this is just a roundabout guess for a package as it is build now # in testing. assert(stream.size > 80000) - # Cached instances should be cleared - assert(Axlsx::Relationship.instances.empty?) + # Cached ids should be cleared + assert(Axlsx::Relationship.ids_cache.empty?) end def test_encrypt From e712b66c9aedb178a5cf550834d05c2bee00cc27 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Fri, 4 Oct 2019 10:02:28 -0700 Subject: [PATCH 18/42] Remove ruby 2.1 and 2.2 from Travis --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d37ee3ba..21702471 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,13 +9,11 @@ notifications: irc: "irc.freenode.org#axlsx" email: recipients: - - digital.ipseity@gmail.com + - noel@peden.biz on_success: always matrix: include: - - rvm: 2.1 - - rvm: 2.2.10 - rvm: 2.3.5 - rvm: 2.4.7 - rvm: 2.5.6 From 1f8f70589be0c7055b510af76e1bbaf7c861ad58 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Fri, 4 Oct 2019 10:49:12 -0700 Subject: [PATCH 19/42] Version 3.0.1 bump [skip ci] --- CHANGELOG.md | 6 ------ README.md | 28 ++++++++++++++++++++-------- axlsx.gemspec | 2 +- lib/axlsx/version.rb | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 901ab193..83d88069 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,5 @@ CHANGELOG --------- -- **April.1.17**:3.0.0-pre - - Support for ruby versions limited to officially supported version - - Updates to dependency gems, especially nokogiri and ruby-zip - - Patch options parsing for two cell anchor - - Remove support for depreciated worksheet members - **November.25.12**:1.3.4 - Support for headers and footers for worksheets - bug fix: Properly escape hyperlink urls @@ -12,7 +7,6 @@ CHANGELOG - Improvements in autowidth calculation. - **November.8.12**:1.3.3 - Patched cell run styles for u and validation for family - - **November.5.12**:1.3.2 - MASSIVE REFACTORING - Patch for apostrophes in worksheet names diff --git a/README.md b/README.md index 114c2bed..44526428 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ Notice: Community Axlsx organization =================================================== All Axlsx related gems have been forked or moved to a community organization: http://github.com/caxlsx * Axlsx -* acts_as_axlsx +* acts_as_caxlsx * axlsx_rails -* activeadmin-axlsx +* activeadmin-caxlsx Please consider helping develop and test these gems. @@ -27,9 +27,9 @@ appreciation for the gem, please don't hesitate to make a donation. **License**: MIT License -**Latest Version**: 3.0.0 +**Latest Version**: 3.0.1 -**Ruby Version**: 2.2.7, 2.3.4, 2.4.1 +**Ruby Version**: 2.3.8, 2.4.5, 2.5.3, 2.6.3 **JRuby Version**: 1.9 modes @@ -127,7 +127,7 @@ To install Axlsx, use the following command: $ gem install caxlsx -#Examples +Examples ------ The example listing is getting overly large to maintain here. @@ -154,7 +154,7 @@ Please see the [examples](https://github.com/caxlsx/axlsx/tree/master/examples/e There is much, much more you can do with this gem. If you get stuck, grab me on IRC or submit an issue to GitHub. Chances are that it has already been implemented. If it hasn't - let's take a look at adding it in. -#Documentation +Documentation -------------- This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use: @@ -163,13 +163,25 @@ This gem is 100% documented with YARD, an exceptional documentation library. To yard server -g -#Specs +Specs ------ This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory. -#Change log +Change log --------- +- **October.4.19**:3.0.1 + - Support for ruby versions limited to officially supported version + - Updates to dependency gems, especially nokogiri and ruby-zip + - Fix Relationship.instances cache + - Autoload fix for Rails +- **September.17.19**:3.0.0 + - First release of caxlsx, fork of axlsx +- **April.1.17**:3.0.0-pre + - Support for ruby versions limited to officially supported version + - Updates to dependency gems, especially nokogiri and ruby-zip + - Patch options parsing for two cell anchor + - Remove support for depreciated worksheet members - ** - Added Cell#name so you you can quickly create a defined name for a single cell in your workbook. - Added full book view and sheet state management. This means you can specify how the workbook renders as well as manage sheet visibility. diff --git a/axlsx.gemspec b/axlsx.gemspec index 7bd72d56..e4260c13 100644 --- a/axlsx.gemspec +++ b/axlsx.gemspec @@ -3,7 +3,7 @@ require File.expand_path('../lib/axlsx/version', __FILE__) Gem::Specification.new do |s| s.name = 'caxlsx' s.version = Axlsx::VERSION - s.authors = ["Randy Morgan", "Jurriaan Pruis", "Noel Peden"] + s.authors = ["Randy Morgan", "Jurriaan Pruis"] s.email = 'noel@peden.biz' s.homepage = 'https://github.com/caxlsx/caxlsx' s.platform = Gem::Platform::RUBY diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index 22a02aa2..d6c7183f 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -1,5 +1,5 @@ module Axlsx # The current version - VERSION = "3.0.0" + VERSION = "3.0.1" end From 07d8ecfa4cb9484cdda179457f6cde87b6d99bb3 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Fri, 4 Oct 2019 10:51:50 -0700 Subject: [PATCH 20/42] Readme title fixes [skip ci] --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 44526428..ff076fde 100644 --- a/README.md +++ b/README.md @@ -261,14 +261,15 @@ related to themes, which axlsx does not implement at this time. - charts do not render -#Thanks! +Thanks! +---------- Open source software is a community effort. None of this could have been done without the help of these awesome folks. -[contributors](https://github.com/caxlsx/axlsx/graphs/contributors) +[contributors](https://github.com/caxlsx/caxlsx/graphs/contributors) -#License +License ---------- Axlsx is licensed under the MIT license. Please see the LICENSE document for more information. From fff65a95da4d2ca9b115781a65d1164823e06636 Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Fri, 4 Oct 2019 11:10:28 -0700 Subject: [PATCH 21/42] Fix rake reference [skip ci] --- Rakefile | 2 +- rubima.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 46b1503e..aa71e48e 100644 --- a/Rakefile +++ b/Rakefile @@ -23,7 +23,7 @@ Rake::TestTask.new do |t| end task :release => :build do - system "gem push axlsx-#{Axlsx::VERSION}.gem" + system "gem push caxlsx-#{Axlsx::VERSION}.gem" end task :default => :test diff --git a/rubima.md b/rubima.md index c28850fe..d5199bc4 100644 --- a/rubima.md +++ b/rubima.md @@ -8,7 +8,7 @@ using CSV, a technology from the 1960's That has changed. There is a new gem, released in November of last year and still under active development that brings more to ruby and ruby on rails than was ever possible before for client reporting. -The gem is axlsx (http://rubygems.org/gems/axlsx) +The gem is caxlsx (http://rubygems.org/gems/caxlsx) Let's take a look at some of the things that it can do for you. From 2224dbc942c15122d2c66f3371a42b502aa2aeab Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Mon, 28 Oct 2019 15:49:45 -0700 Subject: [PATCH 22/42] Use CHANGELOG.md instead of README for changelog --- CHANGELOG.md | 133 +++++++++++++++++++++++++++++++++++++++------------ README.md | 60 ----------------------- 2 files changed, 103 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d88069..4ef11371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,77 @@ CHANGELOG --------- -- **November.25.12**:1.3.4 + +- **October.4.19**: 3.0.1 + - Support for ruby versions limited to officially supported version (Ruby v2.3+) + - Updates to dependency gems, especially nokogiri and ruby-zip + - Fix Relationship.instances cache + - Autoload fix for Rails + +- **September.17.19**: 3.0.0 + - First release of caxlsx, fork of axlsx + +- **April.1.17**: 3.0.0-pre + - Support for ruby versions limited to officially supported version + - Updates to dependency gems, especially nokogiri and ruby-zip + - Patch options parsing for two cell anchor + - Remove support for depreciated worksheet members + - Added Cell#name so you you can quickly create a defined name for a single cell in your workbook. + - Added full book view and sheet state management. This means you can specify how the workbook renders as well as manage sheet visibility. + - Added smoothing management for line charts series + +- **September.12.13**: 2.0.1 + - Unpinned rubyzip version + +- **September.12.13**: 2.0.0 + - DROPPED support for ruby 1.8.7 + - Altered readme to link to contributors + - Lots of improvements to make charts and relations more stable. + - Patched color param mutation. + - Data sourced for pivot tables can now come from other sheets. + - Altered image file extension comparisons to be case insensitive. + - Added control character sanitization to shared strings. + - Added page breaks. see examples/example.rb for an example. + - Bugfix: single to dual cell anchors for images now swap properly so you can set the end_at position during instantiation, in a block or directly on the image. + - Improved how we convert date/time to include the UTC offset when provided. + - Pinned rubyzip to 0.9.9 for those who are not ready to go up. Please note that release 2.0.1 and on will be using the 1.n.n series of rubyzip + - Bugfix: transposition of cells for Worksheet#cols now supports + incongruent column counts.counts + - Added space preservation for cell text. This will allow whitespace + in cell text both when using shared strings and when serializing + directly to the cell. + +- **April.24.13**: 1.3.6 + - Fixed LibreOffice/OpenOffice issue to properly apply colors to lines + in charts. + - Added support for specifying between/notBetween formula in an array. + *thanks* straydogstudio! + - Added standard line chart support. *thanks* scambra + - Fixed straydogstudio's link in the README. *thanks* nogara! + +- **February.4.13**: 1.3.5 + - converted vary_colors for chart data to instance variable with appropriate defulats for the various charts. + - Added trust_input method on Axlsx to instruct the serializer to skip HTML escaping. This will give you a tremendous performance boost, + Please be sure that you will never have <, >, etc in your content or the XML will be invalid. + - Rewrote cell serialization to improve performance + - Added iso_8601 type to support text based date and time management. + - Bug fix for relationahip management in drawings when you add images + and charts to the same worksheet drawing. + - Added outline_level_rows and outline_level_columns to worksheet to simplify setting up outlining in the worksheet. + - Added support for pivot tables + - Added support for descrete border edge styles + - Improved validation of sheet names + - Added support for formula value caching so that iOS and OSX preview can show the proper values. See Cell.add_row and the formula_values option. + +- **November.25.12**: 1.3.4 - Support for headers and footers for worksheets - bug fix: Properly escape hyperlink urls - Improvements in color_scale generation for conditional formatting - Improvements in autowidth calculation. -- **November.8.12**:1.3.3 + +- **November.8.12**: 1.3.3 - Patched cell run styles for u and validation for family -- **November.5.12**:1.3.2 + +- **November.5.12**: 1.3.2 - MASSIVE REFACTORING - Patch for apostrophes in worksheet names - added sheet_by_name for workbook so you can now find your worksheets @@ -15,6 +79,7 @@ CHANGELOG - added insert_worksheet so you can now add a worksheet to an arbitrary position in the worksheets list. - reduced memory consumption for package parts post serialization + - **September.30.12**: 1.3.1 - Improved control character handling - Added stored auto filter values and date grouping items @@ -23,29 +88,35 @@ CHANGELOG all the predefined table styles. - Improved style management for fonts so they merge undefined values from the initial master. + - **September.8.12**: 1.2.3 - enhance exponential float/bigdecimal values rendering as strings intead of 'numbers' in excel. - added support for :none option on chart axis labels - added support for paper_size option on worksheet.page_setup + - **August.27.12**: 1.2.2 - minor patch for auto-filters - minor documentation improvements. + - **August.12.12**: 1.2.1 - Add support for hyperlinks in worksheets - Fix example that was using old style cell merging with concact. - Fix bug that occurs when calculating the font_size for cells that use a user specified style which does not define sz + - **August.5.12**: 1.2.0 - rebuilt worksheet serialization to clean up the code base a bit. - added data labels for charts - added table header printing for each sheet via defined_name. This means that when you print your worksheet, the header rows show for every page -- **July.??.12**: 1.1.9 release + +- **July.??.12**: 1.1.9 - lots of code clean up for worksheet - added in data labels for pie charts, line charts and bar charts. - bugfix chard with data in a sheet that has a space in the name are now auto updating formula based values -- **July.14.12**: 1.1.8 release + +- **July.14.12**: 1.1.8 - added html entity encoding for sheet names. This allows you to use characters like '<' and '&' in your sheet names. - new - first round google docs interoperability @@ -54,7 +125,8 @@ CHANGELOG to PDF from Libra Office - various readability improvements and work standardizing attribute names to snake_case. Aliases are provided for backward compatiblity -- **June.11.12**: 1.1.7 release + +- **June.11.12**: 1.1.7 - fix chart rendering issue when label offset is specified as a percentage in serialization and ensure that formula are not stored in value caches @@ -62,7 +134,8 @@ in value caches - Add title property to axis so you can lable the x/y/series axis for charts. - Add sheet views with panes -- **May.30.12**: 1.1.6 release + +- **May.30.12**: 1.1.6 - data protection with passwords for sheets - cell level input validators - added support for two cell anchors for images @@ -72,14 +145,15 @@ in value caches - added ph (phonetics) and s (style) attributes for row. - resolved all warnings generating from this gem. - improved comment relationship management for multiple comments -- **May.13.12**: 1.1.5 release + +- **May.13.12**: 1.1.5 - MOAR print options! You can now specify paper size, orientation, fit to width, page margings and gridlines for printing. - Support for adding comments to your worksheets - bugfix for applying style to empty cells - bugfix for parsing formula with multiple '=' -- **May.3.12:**: 1.1.4 release +- **May.3.12:**: 1.1.4 - MOAR examples - added outline level for rows and columns - rebuild of numeric and axis data sources for charts @@ -91,23 +165,23 @@ in value caches - Added support for specifying the color of data series in charts. - bugfix using add_cell on row mismanaged calls to update_column_info. -- ** April.25.12:**: 1.1.3 release +- ** April.25.12:**: 1.1.3 - Primarily because I am stupid.....Updates to readme to properly report version, add in missing docs and restructure example directory. -- ** April.25.12:**: 1.1.2 release +- ** April.25.12:**: 1.1.2 - Conditional Formatting completely implemented. - refactoring / documentation for Style#add_style - added in label rotation for chart axis labels - bugfix to properly assign style and type info to cells when only partial information is provided in the types/style option -- ** April.18.12**: 1.1.1 release +- ** April.18.12**: 1.1.1 - bugfix for autowidth calculations across multiple rows - bugfix for dimension calculations with nil cells. - REMOVED RMAGICK dependency WOOT! - Update readme to show screenshot of gem output. - Cleanup benchmark and add benchmark rake task -- ** April.3.12**: 1.1.0 release +- ** April.3.12**: 1.1.0 - bugfix patch name_to_indecies to properly handle extended ranges. - bugfix properly serialize chart title. - lower rake minimum requirement for 1.8.7 apps that don't want to move on to 0.9 NOTE this will be reverted for 2.0.0 with workbook parsing! @@ -122,7 +196,7 @@ in value caches - Major (like 7x faster!) performance updates. - Gem now supports for JRuby 1.6.7, as well as experimental support for Rubinius -- ** March.5.12**: 1.0.18 release +- ** March.5.12**: 1.0.18 https://github.com/randym/axlsx/compare/1.0.17...1.0.18 - bugfix custom borders are not properly applied when using styles.add_style - interop worksheet names must be 31 characters or less or some versions of office complain about repairs @@ -132,14 +206,14 @@ in value caches - added << alias for add_row - removed presetting of date1904 based on authoring platform. Now defaults to use 1900 epoch (date1904 = false) -- ** February.14.12**: 1.0.17 release +- ** February.14.12**: 1.0.17 https://github.com/randym/axlsx/compare/1.0.16...1.0.17 - Added in support for serializing to StringIO - Added in support for using shared strings table. This makes most of the features in axlsx interoperable with iWorks Numbers - Added in support for fixed column_widths - Removed unneeded dependencies on active-support and i18n -- ** February.2.12**: 1.0.16 release +- ** February.2.12**: 1.0.16 https://github.com/randym/axlsx/compare/1.0.15...1.0.16 - Bug fix for schema file locations when validating in rails - Added hyperlink to images @@ -147,14 +221,14 @@ in value caches - removed whitespace/indentation from xml outputs - col_style now skips rows that do not contain cells at the column index -- **January.6.12**: 1.0.15 release +- **January.6.12**: 1.0.15 https://github.com/randym/axlsx/compare/1.0.14...1.0.15 - Bug fix add_style specified number formats must be explicity applied for libraOffice - performance improvements from ochko when creating cells with options. - Bug fix setting types=>[:n] when adding a row incorrectly determines the cell type to be string as the value is null during creation. - Release in preparation for password protection merge -- **December.14.11**: 1.0.14 release +- **December.14.11**: 1.0.14 - Added support for merging cells - Added support for auto filters - Improved auto width calculations @@ -163,14 +237,14 @@ in value caches - Added access to app and core package objects so you can set the creator and other properties of the package - The beginning of password protected xlsx files - roadmapped for January release. -- **December.8.11**: 1.0.13 release +- **December.8.11**: 1.0.13 - Fixing .gemspec errors that caused gem to miss the lib directory. Sorry about that. -- **December.7.11**: 1.0.12 release +- **December.7.11**: 1.0.12 DO NOT USE THIS VERSION = THE GEM IS BROKEN - changed dependency from 'zip' gem to 'rubyzip' and added conditional code to force binary encoding to resolve issue with excel 2011 - Patched bug in app.xml that would ignore user specified properties. -- **December.5.11**: 1.0.11 release +- **December.5.11**: 1.0.11 - Added [] methods to worksheet and workbook to provide name based access to cells. - Added support for functions as cell values - Updated color creation so that two character shorthand values can be used like 'FF' for 'FFFFFFFF' or 'D8' for 'FFD8D8D8' @@ -178,7 +252,7 @@ in value caches - Clean up and support for 1.9.2 and travis integration - Added support for string based cell referencing to chart start_at and end_at. That means you can now use :start_at=>"A1" when using worksheet.add_chart, or chart.start_at ="A1" in addition to passing a cell or the x, y coordinates. -- **October.30.11**: 1.0.10 release +- **October.30.11**: 1.0.10 - Updating gemspec to lower gem version requirements. - Added row.style assignation for updating the cell style for an entire row - Added col_style method to worksheet upate a the style for a column of cells @@ -188,11 +262,11 @@ in value caches - fixed out of range bug in time calculations for 32bit time. - added i18n for active support -- **October.26.11**: 1.0.9 release +- **October.26.11**: 1.0.9 - Updated to support ruby 1.9.3 - Updated to eliminate all warnings originating in this gem -- **October.23.11**: 1.0.8 release +- **October.23.11**: 1.0.8 - Added support for images (jpg, gif, png) in worksheets. - **October.23.11**: 1.0.7 released @@ -206,10 +280,10 @@ in value caches - rebuild of anchor positioning to remove some spagetti code. Chart now supports a start_at and end_at method that accept an arrar for col/row positioning. See example6 for an example. You can still pass :start_at and :end_at options to worksheet.add_chart. - Refactored cat and val axis data to keep series serialization a bit more DRY -##October.22.11: 1.0.6 release +- **October.22.11**: 1.0.6 - Bumping version to include docs. Bug in gemspec pointing to incorrect directory. -##October.22.11: 1.05 +- **October.22.11**: 1.05 - Added support for line charts - Updated examples and readme - Updated series title to be a real title ** NOTE ** If you are accessing titles directly you will need to update text assignation. @@ -225,14 +299,13 @@ in value caches - Added style property to charts - Removed serialization write test as it most commonly fails when run from the gem's intalled directory -##October.21.11: 1.0.4 +- **October.21.11**: 1.0.4 - altered package to accept a filename string for serialization instead of a File object. - Updated specs to conform - More examples for readme -##October.21.11: 1.0.3 release +- **October.21.11**: 1.0.3 - Updated documentation -##October.20.11: 0.1.0 release - +- **October.20.11**: 0.1.0 diff --git a/README.md b/README.md index ff076fde..7cc45c44 100644 --- a/README.md +++ b/README.md @@ -168,66 +168,6 @@ Specs This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory. -Change log ---------- -- **October.4.19**:3.0.1 - - Support for ruby versions limited to officially supported version - - Updates to dependency gems, especially nokogiri and ruby-zip - - Fix Relationship.instances cache - - Autoload fix for Rails -- **September.17.19**:3.0.0 - - First release of caxlsx, fork of axlsx -- **April.1.17**:3.0.0-pre - - Support for ruby versions limited to officially supported version - - Updates to dependency gems, especially nokogiri and ruby-zip - - Patch options parsing for two cell anchor - - Remove support for depreciated worksheet members -- ** - - Added Cell#name so you you can quickly create a defined name for a single cell in your workbook. - - Added full book view and sheet state management. This means you can specify how the workbook renders as well as manage sheet visibility. - - Added smoothing management for line charts series -- **September.12.13**:2.0.1 - - Unpinned rubyzip version -- **September.12.13**:2.0.0 - - DROPPED support for ruby 1.8.7 - - Altered readme to link to contributors - - Lots of improvements to make charts and relations more stable. - - Patched color param mutation. - - Data sourced for pivot tables can now come from other sheets. - - Altered image file extension comparisons to be case insensitive. - - Added control character sanitization to shared strings. - - Added page breaks. see examples/example.rb for an example. - - Bugfix: single to dual cell anchors for images now swap properly so you can set the end_at position during instantiation, in a block or directly on the image. - - Improved how we convert date/time to include the UTC offset when provided. - - Pinned rubyzip to 0.9.9 for those who are not ready to go up. Please note that release 2.0.1 and on will be using the 1.n.n series of rubyzip - - Bugfix: transposition of cells for Worksheet#cols now supports - incongruent column counts.counts - - Added space preservation for cell text. This will allow whitespace - in cell text both when using shared strings and when serializing - directly to the cell. -- **April.24.13**:1.3.6 - - Fixed LibreOffice/OpenOffice issue to properly apply colors to lines - in charts. - - Added support for specifying between/notBetween formula in an array. - *thanks* straydogstudio! - - Added standard line chart support. *thanks* scambra - - Fixed straydogstudio's link in the README. *thanks* nogara! -- **February.4.13**:1.3.5 - - converted vary_colors for chart data to instance variable with appropriate defulats for the various charts. - - Added trust_input method on Axlsx to instruct the serializer to skip HTML escaping. This will give you a tremendous performance boost, - Please be sure that you will never have <, >, etc in your content or the XML will be invalid. - - Rewrote cell serialization to improve performance - - Added iso_8601 type to support text based date and time management. - - Bug fix for relationahip management in drawings when you add images - and charts to the same worksheet drawing. - - Added outline_level_rows and outline_level_columns to worksheet to simplify setting up outlining in the worksheet. - - Added support for pivot tables - - Added support for descrete border edge styles - - Improved validation of sheet names - - Added support for formula value caching so that iOS and OSX preview can show the proper values. See Cell.add_row and the formula_values option. - -Please see the {file:CHANGELOG.md} document for past release information. - # Known interoperability issues. As axslx implements the Office Open XML (ECMA-376 spec) much of the functionality is interoperable with other spreadsheet software. Below is From 76975a38e56b3cb3d13ed4e2b59afb0d2aaaef0f Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Mon, 28 Oct 2019 16:41:20 -0700 Subject: [PATCH 23/42] Remove rubima.md --- rubima.md | 74 ------------------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 rubima.md diff --git a/rubima.md b/rubima.md deleted file mode 100644 index d5199bc4..00000000 --- a/rubima.md +++ /dev/null @@ -1,74 +0,0 @@ -Axlsx – The end of CSV as an excuse for client reporting. - -One of the things that keeps popping up for ruby and ruby on rails application developers is client reporting. -We have tools for creating beautiful screen based reports that make the end user say “WOW”, we can even - -with the help of a great designer - produce a well formatted PDF. But when it comes to data, we are still -using CSV, a technology from the 1960's - -That has changed. There is a new gem, released in November of last year and still under active development -that brings more to ruby and ruby on rails than was ever possible before for client reporting. - -The gem is caxlsx (http://rubygems.org/gems/caxlsx) - -Let's take a look at some of the things that it can do for you. - -1. The Basics -The basics of generating and serializing xlsx data are dead simple. - -1. Create a package -2. Setup your styles -3. add a worksheet to the workbook -3. add your data, charts, images, conditional formatting, data - validations, page setup, print options, and password locking, -comments, cell merges and panes. -4. serialize - -The code below illustrates a trivial example a few of these items - -'''ruby -require 'axlsx' - -package = Axlsx::Package.new -styles = package.workbook.styles - -header = styles.add_style :bg_color => '00', :fg_color => 'FF', :sz => 16, :alignment => { :horizontal => :center } - -quarter_label = styles.add_style :bg_color => 'FFDFDEDF', :alignment => { :indent => 1 }, :sz => 14 - -money = styles.add_style :num_fmt => 5, :zd => 14 - -package.workbook.add_worksheet do |worksheet| - worksheet.add_row ['Revenue by Quarter'], :style => header - worksheet.merge_cells 'A1:I1' - worksheet.add_row - data_row_style = [nil, quarter_label, money] - - worksheet.add_row [nil, 'Q1', 35221124], :style => data_row_style - worksheet.add_row [nil, 'Q2', 56742113], :style => data_row_style - worksheet.add_row [nil, 'Q3', 71165443], :style => data_row_style - worksheet.add_row [nil, 'Q4', 98761111], :style => data_row_style - - worksheet.add_chart(Axlsx::Bar3DChart, :bar_dir => :col) do |chart| - chart.start_at 4, 2 - chart.end_at 9, 15 - chart.title = worksheet['A1'] - chart.add_series :data => worksheet['C3:C6'], :labels => worksheet['B3:B6'] - end -end -package.serialize 'the_better_basics.xlsx' - -If you are using rails, there is a sister gem acts_as_xlsx (http://rubygems.org/gems/axlsx) -That is going to make you smile as well. - -Have a look at these two blog posts for a quick write up of how easy it -is to use. - -http://axlsx.blogspot.jp/2011/12/using-actsasxlsx-to-generate-excel-data.html -http://axlsx.blogspot.jp/2011/12/axlsx-making-excel-reports-with-ruby-on.html - - - - - - - From 2cdaed0178d95c8f0e63ae60c94cfd8bd787e5c6 Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Mon, 28 Oct 2019 16:54:54 -0700 Subject: [PATCH 24/42] Add Style Reference --- README.md | 10 ++- .../header_and_footer_codes.md | 0 docs/style_reference.md | 82 +++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) rename notes_on_header_footer.md => docs/header_and_footer_codes.md (100%) create mode 100644 docs/style_reference.md diff --git a/README.md b/README.md index 7cc45c44..e62bc1d0 100644 --- a/README.md +++ b/README.md @@ -157,11 +157,15 @@ There is much, much more you can do with this gem. If you get stuck, grab me on Documentation -------------- -This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use: +Detailed documentation is available at: - gem install yard kramdown +[https://www.rubydoc.info/gems/caxlsx/](https://www.rubydoc.info/gems/caxlsx/) + +Additional documentation is listed below: + +- [Style Reference](https://github.com/caxlsx/caxlsx/blob/master/docs/style_reference.md) +- [Header and Footer Codes](https://github.com/caxlsx/caxlsx/blob/master/docs/header_and_footer_codes.md) - yard server -g Specs ------ diff --git a/notes_on_header_footer.md b/docs/header_and_footer_codes.md similarity index 100% rename from notes_on_header_footer.md rename to docs/header_and_footer_codes.md diff --git a/docs/style_reference.md b/docs/style_reference.md new file mode 100644 index 00000000..01d7f008 --- /dev/null +++ b/docs/style_reference.md @@ -0,0 +1,82 @@ +# Basic Styling +- `b` (Boolean) - Bold +- `i` (Boolean) - Italic +- `u` (Boolean) - Underline +- `fg_color` (String) - Text Color - Ex: `000000` +- `bg_color` (String) - Cell background color - Ex: `CCCCCC` +- `alignment` (Hash) - Text alignment. + - Available sub-options are `:horizontal`, `:vertical`, `:wrap_text`. + - Example: `alignment: {horizontal: true, vertical: true, wrap_text: false}` +- `strike` (Boolean) - Indicates if the text should be rendered with a strikethrough +- `outline` (Boolean) - Indicates if the text should be rendered with a shadow +- `sz` (Integer) - Font Size +- `font_name` (String) - Font Name - Ex. `Arial` +- `family` (Integer) - The font family to use. Options are: + - `1` - Roman (Default) + - `2` - Swiss + - `3` - Modern + - `4` - Script + - `5` - Decorative +- `charset` (Integer) - The character set to use. Axlsx documentation says this setting is ignored most of the time. +- `type` (Symbol) - Type of the cell. Options are: `:xf` (Default) or `:dxf` +- `border` (Hash) - Borders support style, color and edges options. Example: `border: {style: :thin, color: "000000", edges: [:top, :bottom, :left, :right]}`. Available styles for the border are: + - `:none` + - `:thin` + - `:medium` + - `:dashed` + - `:dotted` + - `:thick` + - `:double` + - `:hair` + - `:mediumDashed` + - `:dashDot` + - `:mediumDashDot` + - `:dashDotDot` + - `:mediumDashDotDot` + - `:slantDashDot` +- `hidden` (Boolean) - Indicates if the cell should be hidden +- `locked` (Boolean) - Indicates if the cell should be locked +- `format_code` (String) - See section below +- `num_fmt` (Integer) - See section below + +# `format_code` and `num_fmt` +To output a dollar sign, comma's every three values, and minumum two decimal places use: +`format_code: '\$#,##0.00'` + +This will output a nicely formatted date/time: +`m/d/yyyy h:mm:ss AM/PM` + +I think its much more preferable to write out the `format_code` manually instead of using `num_fmt` however the option is there. + +Heres a list of the `num_fmt` code (left side) and corresponding `format_code` string (right side) + +- `1` - `'0'` +- `2` - `'0.00'` +- `3` - `'#,##0'` +- `4` - `'#,##0.00'` +- `5` - `'$#,##0_);($#,##0)'` +- `6` - `'$#,##0_);Red'` +- `7` - `'$#,##0.00_);($#,##0.00)'` +- `8` - `'$#,##0.00_);Red'` +- `9` - `'0%'` +- `10` - `'0.00%' ` +- `11` - `'0.00E+00'` +- `12` - `'# ?/?'` +- `13` - `'# ??/??'` +- `14` - `'m/d/yyyy'` +- `15` - `'d-mmm-yy'` +- `16` - `'d-mmm'` +- `17` - `'mmm-yy'` +- `18` - `'h:mm AM/PM'` +- `19` - `'h:mm:ss AM/PM'` +- `20` - `'h:mm'` +- `21` - `'h:mm:ss'` +- `22` - `'m/d/yyyy h:mm'` +- `37` - `'#,##0_);(#,##0) 38 #,##0_);Red'` +- `39` - `'#,##0.00_);(#,##0.00)'` +- `40` - `'#,##0.00_);Red'` +- `45` - `'mm:ss'` +- `46` - `'[h]:mm:ss'` +- `47` - `'mm:ss.0'` +- `48` - `'##0.0E+0'` +- `49` - `'@'` From eaa635a3e4a519556d9e6fe0191afba9aa9125d7 Mon Sep 17 00:00:00 2001 From: Ali Mujtaba Date: Tue, 15 Oct 2019 00:37:56 +0500 Subject: [PATCH 25/42] fix validate document with font option underline --- lib/axlsx/stylesheet/font.rb | 12 ++++++++++-- test/stylesheet/tc_font.rb | 16 ++++++++++++++-- test/stylesheet/tc_styles.rb | 28 +++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb index baa1ef83..d9a4a4d8 100644 --- a/lib/axlsx/stylesheet/font.rb +++ b/lib/axlsx/stylesheet/font.rb @@ -76,7 +76,10 @@ def initialize(options={}) attr_reader :i # Indicates if the font should be rendered underlined - # @return [Boolean] + # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true, false + # @return [String] + # @note + # true or false is for backwards compatibility and is reassigned to :single or :none respectively attr_reader :u # Indicates if the font should be rendered with a strikthrough @@ -118,7 +121,12 @@ def b=(v) Axlsx::validate_boolean v; @b = v end # @see i def i=(v) Axlsx::validate_boolean v; @i = v end # @see u - def u=(v) Axlsx::validate_boolean v; @u = v end + def u=(v) + v = :single if (v == true || v == 1 || v == :true || v == 'true') + v = :none if (v == false || v == 0 || v == :false || v == 'false') + Axlsx::validate_cell_u v + @u = v + end # @see strike def strike=(v) Axlsx::validate_boolean v; @strike = v end # @see outline diff --git a/test/stylesheet/tc_font.rb b/test/stylesheet/tc_font.rb index 7b3da25a..4d548d7c 100644 --- a/test/stylesheet/tc_font.rb +++ b/test/stylesheet/tc_font.rb @@ -62,11 +62,23 @@ def test_i assert_equal(@item.i, true) end - # def u=(v) Axlsx::validate_boolean v; @u = v end + # def u=(v) Axlsx::validate_cell_u v; @u = v end def test_u assert_raise(ArgumentError) { @item.u = -7 } + assert_nothing_raised { @item.u = :single } + assert_equal(@item.u, :single) + doc = Nokogiri::XML(@item.to_xml_string) + assert(doc.xpath('//u[@val="single"]')) + end + + def test_u_backward_compatibility + # backward compatibility for true assert_nothing_raised { @item.u = true } - assert_equal(@item.u, true) + assert_equal(@item.u, :single) + + # backward compatibility for false + assert_nothing_raised { @item.u = false } + assert_equal(@item.u, :none) end # def strike=(v) Axlsx::validate_boolean v; @strike = v end diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index eb1680ad..72bf1466 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -124,7 +124,7 @@ def test_parse_font_options :sz => 20, :b => 1, :i => 1, - :u => 1, + :u => :single, :strike => 1, :outline => 1, :shadow => 1, @@ -232,4 +232,30 @@ def test_multiple_dxf style = @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf assert_equal(1, style, "returns the second dxfId") end + + def test_valid_document_with_font_options + font_options = { + :fg_color => "FF050505", + :sz => 20, + :b => 1, + :i => 1, + :u => :single, + :strike => 1, + :outline => 1, + :shadow => 1, + :charset => 9, + :family => 1, + :font_name => "woot font" + } + @styles.add_style font_options + + schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) + doc = Nokogiri::XML(@styles.to_xml_string) + errors = [] + schema.validate(doc).each do |error| + errors.push error + puts error.message + end + assert(errors.size == 0) + end end From c886ae136a947d8c0b2910ece73e553f603d48e2 Mon Sep 17 00:00:00 2001 From: vzvu3k6k Date: Fri, 25 Oct 2019 00:59:55 +0900 Subject: [PATCH 26/42] Remove a typo from comment Fixnum is removed by 12d6433, but this typo was remained. --- lib/axlsx/util/validators.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 71652ef2..76ee2250 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -92,7 +92,7 @@ def self.validate_unsigned_int(v) # Requires that the value is a Integer or Float and is greater or equal to 0 # @param [Any] v The value validated - # @raise [ArgumentError] raised if the value is not a Fixnun, Integer, Float value greater or equal to 0 + # @raise [ArgumentError] raised if the value is not a Integer, Float value greater or equal to 0 # @return [Boolean] true if the data is valid def self.validate_unsigned_numeric(v) DataTypeValidator.validate(:unsigned_numeric, Numeric, v, UINT_VALIDATOR) From 2d77319dd857f71756dcb72d5a0d13db06e48c2d Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Mon, 28 Oct 2019 16:04:46 -0700 Subject: [PATCH 27/42] Improve README --- README.md | 138 +++++++++++++++--------------------------------------- 1 file changed, 39 insertions(+), 99 deletions(-) diff --git a/README.md b/README.md index e62bc1d0..8dd4dc41 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,14 @@ -Notice: Community Axlsx organization -=================================================== -All Axlsx related gems have been forked or moved to a community organization: http://github.com/caxlsx -* Axlsx -* acts_as_caxlsx -* axlsx_rails -* activeadmin-caxlsx - -Please consider helping develop and test these gems. - -Axlsx: Office Open XML Spreadsheet Generation -==================================== +# Axlsx (Community Continued Version) [![Build Status](https://travis-ci.com/caxlsx/caxlsx.svg?branch=master)](https://travis-ci.com/caxlsx/caxlsx) -If you are using axlsx for commercial purposes, or just want to show your -appreciation for the gem, please don't hesitate to make a donation. +## Notice: Community Axlsx Organization -**IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx) +To better maintain the Axlsx ecosystem, all related gems have been forked or moved to the following community organization: -**Git**:[http://github.com/caxlsx/caxlsx](http://github.com/caxlsx/caxlsx) +http://github.com/caxlsx -**Google Group**: [https://groups.google.com/forum/?fromgroups#!forum/axlsx](https://groups.google.com/forum/?fromgroups#!forum/axlsx) -**Author**: Randy Morgan - -**Copyright**: 2011 - 2017 - -**License**: MIT License - -**Latest Version**: 3.0.1 - -**Ruby Version**: 2.3.8, 2.4.5, 2.5.3, 2.6.3 - -**JRuby Version**: 1.9 modes - -**Rubinius Version**: rubinius 3 * lower versions may run, this gem always tests against head. - -**Release Date**: September 12th 2013 - -If you are working in rails, or with active record see: -[acts_as_caxlsx](http://github.com/caxlsx/acts_as_caxlsx) - -acts_as_caxlsx is a simple ActiveRecord mixin that lets you generate a workbook with: - -```ruby -Posts.where(created_at > Time.now-30.days).to_xlsx -``` - -** and ** - -* http://github.com/caxlsx/axlsx_rails -Axlsx_Rails provides an Axlsx renderer so you can move all your spreadsheet code from your controller into view files. Partials are supported so you can organize any code into reusable chunks (e.g. cover sheets, common styling, etc.) You can use it with acts_as_xlsx, placing the to_xlsx call in a view and add ':package => xlsx_package' to the parameter list. Now you can keep your controllers thin! - -There are guides for using axlsx and acts_as_xlsx here: -[http://axlsx.blog.randym.net](http://axlsx.blog.randym.net) - -If you are working with ActiveAdmin see: - -[activeadmin-caxlsx](http://github.com/caxlsx/activeadmin-caxlsx) - -It provides a plugin and dsl for generating downloadable reports. - -The examples directory contains a number of more specific examples as -well. - -Synopsis --------- +## 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. @@ -72,9 +16,7 @@ With Axlsx you can create excel worksheets with charts, images (with links), aut ![Screen 1](https://github.com/caxlsx/axlsx/raw/master/examples/sample.png) - -Feature List ------------- +## Feature List 1. Author xlsx documents: Axlsx is made to let you easily and quickly generate professional xlsx based reports that can be validated before serialization. @@ -120,15 +62,14 @@ and Numbers 22. Page Breaks -Installing ----------- -To install Axlsx, use the following command: +## Install - $ gem install caxlsx +```ruby +gem 'caxlsx' +``` -Examples ------- +## Examples The example listing is getting overly large to maintain here. If you are using Yard, you will be able to see the examples in line below. @@ -150,12 +91,10 @@ end Please see the [examples](https://github.com/caxlsx/axlsx/tree/master/examples/example.rb) for more. -{include:file:examples/example.rb} +There is much, much more you can do with this gem. Chances are that it has already been implemented. If it hasn't, let's take a look at adding it in. -There is much, much more you can do with this gem. If you get stuck, grab me on IRC or submit an issue to GitHub. Chances are that it has already been implemented. If it hasn't - let's take a look at adding it in. -Documentation --------------- +## Documentation Detailed documentation is available at: @@ -166,13 +105,20 @@ Additional documentation is listed below: - [Style Reference](https://github.com/caxlsx/caxlsx/blob/master/docs/style_reference.md) - [Header and Footer Codes](https://github.com/caxlsx/caxlsx/blob/master/docs/header_and_footer_codes.md) +## Plugins & Integrations + +Currently the following additional gems are available: -Specs ------- +- [acts_as_caxlsx](https://github.com/caxlsx/acts_as_caxlsx) + * Provides simple ActiveRecord integration +- [axlsx_rails](https://github.com/caxlsx/axlsx_rails) + * Provides a `.axlsx` renderer to Rails so you can move all your spreadsheet code from your controller into view files. +- [activeadmin-caxlsx](https://github.com/caxlsx/activeadmin-caxlsx) + * An Active Admin plugin that includes DSL to create downloadable reports. -This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory. -# Known interoperability issues. +## Known Software Interoperability Issues + As axslx implements the Office Open XML (ECMA-376 spec) much of the functionality is interoperable with other spreadsheet software. Below is a listing of some known issues. @@ -189,31 +135,25 @@ related to themes, which axlsx does not implement at this time. - Images are known to not work with google docs - border colors do not work -3. Numbers - - you must set 'use_shared_strings' to true. This is most - conveniently done just before rendering by calling Package.use_shared_strings = true prior to serialization. - - ```ruby - p = Axlsx::Package.new - p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet| - sheet.add_row ["First Column", "Second", "Third"] - sheet.add_row [1, 2, 3] - end - p.use_shared_strings = true - p.serialize('simple.xlsx') - ``` +3. Apple Numbers - charts do not render + - you must set 'use_shared_strings' to true. This is most conveniently done just before rendering by calling Package.use_shared_strings = true prior to serialization. +```ruby +p = Axlsx::Package.new +p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet| + sheet.add_row ["First Column", "Second", "Third"] + sheet.add_row [1, 2, 3] +end +p.use_shared_strings = true +p.serialize('simple.xlsx') +``` -Thanks! ----------- -Open source software is a community effort. None of this could have been -done without the help of these awesome folks. +## Credits -[contributors](https://github.com/caxlsx/caxlsx/graphs/contributors) +Originally created by Randy Morgan - @randym -License ----------- +Forked in 2019, to enable the community to maintain the Axlsx ecosystem - http://github.com/caxlsx -Axlsx is licensed under the MIT license. Please see the LICENSE document for more information. +Open source software is a community effort. None of this could have been done without the help of [our Contributors](https://github.com/caxlsx/caxlsx/graphs/contributors). From f31c46ce08541a432e732cd093f916e37853807b Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Mon, 28 Oct 2019 22:53:38 -0700 Subject: [PATCH 28/42] Delete appveyor.yml --- appveyor.yml | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index c2fd1547..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,26 +0,0 @@ -version: 2.1.0.{build}-{branch} - -environment: - matrix: - - RUBY_VERSION: 26 - - RUBY_VERSION: 25 - - RUBY_VERSION: 24 - - RUBY_VERSION: 23 - - RUBY_VERSION: 22 - - RUBY_VERSION: 21 - - RUBY_VERSION: 200 - - RUBY_VERSION: 193 - -install: - - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% - - bundle install - -build: off - -before_test: - - ruby -v - - gem -v - - bundle -v - -test_script: - - bundle exec rake From 887f337e2c69be4179e79b281efc971e4dd08f9f Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Thu, 31 Oct 2019 00:06:30 +0100 Subject: [PATCH 29/42] Create CONTRIBUTING.md --- CONTRIBUTING.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..e8f55b66 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# How to contribute to caxlsx + +## Did you find a bug? + + * **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/caxlsx/caxlsx/issues) and [Pull requests](https://github.com/caxlsx/caxlsx/pulls). + + * If you're unable to find an open issue or pull request addressing the problem, [create a new issue](https://github.com/caxlsx/caxlsx/issues/new) or – ideally – a new [pull request](https://github.com/caxlsx/caxlsx/pulls). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring. It’s important that others can reproduce the problem easily. + + * A pull request must contain tests covering the behaviour added or modified by the pull request. + + +## Do you intend to add a new feature or change an existing one? + + * Refer to the guidelines mentioned above. Note that a feature request not accompanied by actual code (in form of a pull request) is rather unlikely to be implemented. + + +## Helping to resolve existing issues + +Triaging issues can be very time-consuming, so we especially appreciate any help in this area! + +Start by looking for (issues labelled “needs triage”)[https://github.com/caxlsx/caxlsx/labels/needs%20triage]. Choose one of these issues, then perform the following checks: + + * Is the issue still relevant? It may have been fixed or made obsolete in the meantime. + * Can the issue be reproduced? If necessary, ask the person who reported the issue originally to provide more information. + * If an issue is very vague, can you help narrow it down to something more specific? Maybe you can provide additional information to help reproduce a bug, or help by eliminating needless steps that aren't required to demonstrate the problem. + * Is it clear which portion of the caxlsx code is causing the issue? If not, try to determine the relevant code. + * How did the relevant code came into the state causing the issue? Has it been there since the beginning, or is it the result of some later change? + +Add comments to the issue to share your findings. Anything you can do to make bug reports more succinct or easier to reproduce helps folks trying to write code to fix those bugs - whether you end up writing the code yourself or not. + +--- + +_A lot of the content in this document was ~~inspired by~~ copied from the [Ruby on Rails Contributing Guidelines](https://github.com/rails/rails/blob/master/CONTRIBUTING.md)_ From 45280b42a0fc4e907c4496a3bf9026522543854a Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Thu, 31 Oct 2019 00:08:26 +0100 Subject: [PATCH 30/42] Add link to contribution guidelines --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8dd4dc41..d3b7d476 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ and Numbers gem 'caxlsx' ``` +## Contributing + +See [CONTRIBUTING.md](https://github.com/caxlsx/caxlsx/blob/master/CONTRIBUTING.md) + ## Examples The example listing is getting overly large to maintain here. From 345748bfa26ee75e7b047736da1d993427da9e18 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sat, 23 Nov 2019 12:40:59 +0100 Subject: [PATCH 31/42] Add link to FAQ --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d3b7d476..8d6cb786 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ Detailed documentation is available at: Additional documentation is listed below: +- [FAQ](https://github.com/caxlsx/caxlsx/wiki/FAQ) (work in progress) - [Style Reference](https://github.com/caxlsx/caxlsx/blob/master/docs/style_reference.md) - [Header and Footer Codes](https://github.com/caxlsx/caxlsx/blob/master/docs/header_and_footer_codes.md) From c1307a3fff72e86074ae19b3d33f79ebebd5e3e6 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sat, 23 Nov 2019 13:06:48 +0100 Subject: [PATCH 32/42] Add section about where to (not) post questions and find answers. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8d6cb786..2705f037 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,10 @@ Additional documentation is listed below: - [Style Reference](https://github.com/caxlsx/caxlsx/blob/master/docs/style_reference.md) - [Header and Footer Codes](https://github.com/caxlsx/caxlsx/blob/master/docs/header_and_footer_codes.md) +⚠ Please __do not create issues__ for questions regarding the usage of axlsx / caxlsx. Look through this README, the [examples](https://github.com/caxlsx/axlsx/tree/master/examples/example.rb), and the [FAQ](https://github.com/caxlsx/caxlsx/wiki/FAQ), and also check [questions tagged `axlsx` on Stack Overflow](https://stackoverflow.com/questions/tagged/axlsx). + +Feel free to add your question (including an answer!) to the FAQ if you think it is of general interest. + ## Plugins & Integrations Currently the following additional gems are available: From bf2cb814f65a1111715a698570b658d20ceb5a5b Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Tue, 3 Dec 2019 13:11:58 +0100 Subject: [PATCH 33/42] Remove unused / stubbed code related to parsing xlsx files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This code was added in 3def8f8895 (back in 2011). It has never been worked on further since; `Axlsx::Parser` is not used anywhere in the whole codebase. Currently there are no plans to support parsing xlsx file anytime soon, so let‘s remove all of this dead code. --- lib/axlsx.rb | 2 -- lib/axlsx/package.rb | 8 ------- lib/axlsx/util/parser.rb | 44 ---------------------------------- lib/axlsx/workbook/workbook.rb | 9 ------- 4 files changed, 63 deletions(-) delete mode 100644 lib/axlsx/util/parser.rb diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 23fc6c8b..e60660b6 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -9,8 +9,6 @@ require 'axlsx/util/accessors.rb' require 'axlsx/util/serialized_attributes' require 'axlsx/util/options_parser' -# to be included with parsable intitites. -#require 'axlsx/util/parser.rb' require 'axlsx/util/mime_type_utils' require 'axlsx/stylesheet/styles.rb' diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 56410339..56047f02 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -68,13 +68,6 @@ def workbook @workbook end - #def self.parse(input, confirm_valid = false) - # p = Package.new - # z = Zip::File.open(input) - # p.workbook = Workbook.parse z.get_entry(WORKBOOK_PN) - # p - #end - # @see workbook def workbook=(workbook) DataTypeValidator.validate :Package_workbook, Workbook, workbook; @workbook = workbook; end @@ -355,4 +348,3 @@ def relationships end end end - diff --git a/lib/axlsx/util/parser.rb b/lib/axlsx/util/parser.rb deleted file mode 100644 index 78b819bd..00000000 --- a/lib/axlsx/util/parser.rb +++ /dev/null @@ -1,44 +0,0 @@ -# encoding: UTF-8 -module Axlsx - # The Parser module mixes in a number of methods to help in generating a model from xml - # This module is not included in the axlsx library at this time. It is for future development only, - module Parser - - # The xml to be parsed - attr_accessor :parser_xml - - # parse and assign string attribute - def parse_string attr_name, xpath - send("#{attr_name}=", parse_value(xpath)) - end - - # parse convert and assign node text to symbol - def parse_symbol attr_name, xpath - v = parse_value xpath - v = v.to_sym unless v.nil? - send("#{attr_name}=", v) - end - - # parse, convert and assign note text to integer - def parse_integer attr_name, xpath - v = parse_value xpath - v = v.to_i if v.respond_to?(:to_i) - send("#{attr_name}=", v) - end - - # parse, convert and assign node text to float - def parse_float attr_name, xpath - v = parse_value xpath - v = v.to_f if v.respond_to?(:to_f) - send("#{attr_name}=", v) - end - - # return node text based on xpath - def parse_value xpath - node = parser_xml.xpath(xpath) - return nil if node.empty? - node.text.strip - end - - end -end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 7572e51f..48b7f882 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -197,15 +197,6 @@ def sheet_by_name(name) @worksheets[index] if index end - # lets come back to this later when we are ready for parsing. - #def self.parse entry - # io = entry.get_input_stream - # w = self.new - # w.parser_xml = Nokogiri::XML(io.read) - # w.parse_string :date1904, "//xmlns:workbookPr/@date1904" - # w - #end - # Creates a new Workbook # The recomended way to work with workbooks is via Package#workbook # @option options [Boolean] date1904. If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false. From 2f71254fe094df11e645851616f36c0f4e1e2b51 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sat, 14 Dec 2019 23:53:39 +0100 Subject: [PATCH 34/42] Add GitHub action for closing stale issues --- .github/workflows/stale.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 00000000..e51cf505 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,29 @@ +name: Mark stale issues and pull requests + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + stale: + + runs-on: ubuntu-latest + + steps: + - uses: actions/stale@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + days-before-stale: 90 + days-before-close: 7 + stale-issue-message: > + This issue has been automatically marked as stale because it has not been commented on for at least three months. + It will be automatically closed in 7 days. + + If you have any new information or updates please reply in order to keep the issue open. + stale-pr-message: > + This pull request has been automatically marked as stale because has been no activity for at least three months. + It will be automatically closed in 7 days. + + If you have any new information or updates please reply in order to keep the pull request open. + stale-issue-label: stale + stale-pr-label: stale From 45a091e94282ad8bd29666dbcca23c440d30cc27 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sun, 15 Dec 2019 00:39:59 +0100 Subject: [PATCH 35/42] Add changelog entry for 2.0.2 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ef11371..08ce0810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG - Fix Relationship.instances cache - Autoload fix for Rails +- **October.4.19**: 2.0.2 + - Released as caxlsx, fork of axlsx + - Update ruby-zip dependency (fixes https://github.com/randym/axlsx/issues/536) + - **September.17.19**: 3.0.0 - First release of caxlsx, fork of axlsx From 19b48592bb241bcc40057cbfafd9058d9b0d9a87 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sun, 15 Dec 2019 17:00:09 +0100 Subject: [PATCH 36/42] Mention axslx_styler in related gems section --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2705f037..0c2c1268 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Additional documentation is listed below: Feel free to add your question (including an answer!) to the FAQ if you think it is of general interest. -## Plugins & Integrations +## Plugins, Integrations, and Extensions Currently the following additional gems are available: @@ -124,7 +124,8 @@ Currently the following additional gems are available: * Provides a `.axlsx` renderer to Rails so you can move all your spreadsheet code from your controller into view files. - [activeadmin-caxlsx](https://github.com/caxlsx/activeadmin-caxlsx) * An Active Admin plugin that includes DSL to create downloadable reports. - +- [axlsx_styler](https://github.com/axlsx-styler-gem/axlsx_styler) + * Allows you to build clean and maintainable styles for your axlsx spreadsheets. Build your spreadsheeet with data and then apply styles later. ## Known Software Interoperability Issues From 8cc722d23d6c4abb2a9cd60ed076e40ab7897450 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sun, 15 Dec 2019 18:30:46 +0100 Subject: [PATCH 37/42] Fix typo. See https://github.com/randym/axlsx/pull/617 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08ce0810..720fa9d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,7 +58,7 @@ CHANGELOG Please be sure that you will never have <, >, etc in your content or the XML will be invalid. - Rewrote cell serialization to improve performance - Added iso_8601 type to support text based date and time management. - - Bug fix for relationahip management in drawings when you add images + - Bug fix for relationship management in drawings when you add images and charts to the same worksheet drawing. - Added outline_level_rows and outline_level_columns to worksheet to simplify setting up outlining in the worksheet. - Added support for pivot tables From 5f0d84dd5f1abf8ecf5b3688dcd8c4af070b0ee4 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sun, 15 Dec 2019 18:32:11 +0100 Subject: [PATCH 38/42] Fix typo. See https://github.com/randym/axlsx/pull/635 --- lib/axlsx/workbook/worksheet/cell.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index fb10ad36..99b3f8b0 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -12,7 +12,7 @@ class Cell # @param [Row] row The row this cell belongs to. # @param [Any] value The value associated with this cell. - # @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided. + # @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the value provided. # @option options [Integer] style The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied. # @option options [String] font_name # @option options [Integer] charset From 198f6b7f9203451898d9fef0c7ecf12eabe1a02f Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sun, 15 Dec 2019 18:39:20 +0100 Subject: [PATCH 39/42] Fix typo See https://github.com/randym/axlsx/pull/606 --- lib/axlsx/package.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 56047f02..41bfdb11 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -132,7 +132,7 @@ def encrypt(file_name, password) # dcterms and xml namespaces. Those remote schema are included in this gem, and the original files have been altered to # refer to the local versions. # - # If by chance you are able to creat a package that does not validate it indicates that the internal + # 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 # @example From 75cec07c450378a597c8bbae1ca10229b6fb2bf1 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Sun, 15 Dec 2019 19:27:18 +0100 Subject: [PATCH 40/42] Fix rdoc for BarSeries#shape --- lib/axlsx/drawing/bar_series.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb index a649a68a..d266dd09 100644 --- a/lib/axlsx/drawing/bar_series.rb +++ b/lib/axlsx/drawing/bar_series.rb @@ -15,9 +15,8 @@ class BarSeries < Series # @return [Array, SimpleTypedList] attr_reader :labels - # The shabe of the bars or columns - # must be one of [:percentStacked, :clustered, :standard, :stacked] - # @return [Symbol] + # The shape of the bars or columns + # @return [Symbol] must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax] attr_reader :shape # An array of rgb colors to apply to your bar chart. @@ -41,8 +40,7 @@ def initialize(chart, options={}) # @see colors def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end - # The shabe of the bars or columns - # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax] + # @see shape def shape=(v) RestrictionValidator.validate "BarSeries.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v @shape = v From cfce288c6dfffb7118d06fe0e5511d92cc98c722 Mon Sep 17 00:00:00 2001 From: Ian Clarkson Date: Mon, 16 Dec 2019 09:17:41 -0800 Subject: [PATCH 41/42] Check size in bytes as opposed to string size - `size` returns length in characters, but doesn't factor in multibyte Unicode characters. By switching to `bytesize`, we check the relevant measure of how many bytes the worksheet name is. - Fixes https://github.com/randym/axlsx/issues/588 - Copy of PR against original axlsx (https://github.com/randym/axlsx/pull/589) --- lib/axlsx/workbook/worksheet/worksheet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 6fbd384e..9cfefa51 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -656,7 +656,7 @@ def outline(collection, range, level = 1, collapsed = true) def validate_sheet_name(name) DataTypeValidator.validate :worksheet_name, String, name - raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.size > 31 + raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.bytesize > 31 raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char } name = Axlsx::coder.encode(name) sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name } From 23a4fa5b323c22ce0e5910ae9c02b9fe54151d18 Mon Sep 17 00:00:00 2001 From: Ian Clarkson Date: Mon, 16 Dec 2019 16:10:47 -0800 Subject: [PATCH 42/42] Add test for name too long with Unicode characters --- test/workbook/worksheet/tc_worksheet.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index fa8832d8..a67e97dd 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -29,6 +29,10 @@ def test_name_exception_on_invalid_character assert_raises(ArgumentError) { @ws.name = 'foo?bar' } end + def test_name_on_name_too_long + assert_raises(ArgumentError) { @ws.name = '123456789012345678901234567890¡' } + end + def test_page_margins assert(@ws.page_margins.is_a? Axlsx::PageMargins) end