spreadsheet_architect 2.1.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +17 -2
- data/README.md +149 -129
- data/lib/spreadsheet_architect/class_methods/csv.rb +2 -2
- data/lib/spreadsheet_architect/class_methods/ods.rb +2 -2
- data/lib/spreadsheet_architect/class_methods/xlsx.rb +26 -30
- data/lib/spreadsheet_architect/exceptions.rb +32 -30
- data/lib/spreadsheet_architect/utils/xlsx.rb +46 -25
- data/lib/spreadsheet_architect/utils.rb +116 -121
- data/lib/spreadsheet_architect/version.rb +1 -1
- data/lib/spreadsheet_architect.rb +5 -1
- data/test/dummy_app/app/models/active_model_object.rb +1 -0
- data/test/dummy_app/app/models/custom_post.rb +1 -0
- data/test/dummy_app/app/models/legacy_plain_ruby_object.rb +14 -0
- data/test/dummy_app/app/models/plain_ruby_object.rb +2 -9
- data/test/dummy_app/app/models/post.rb +3 -0
- data/test/dummy_app/config/routes.rb +4 -5
- data/test/dummy_app/db/test.sqlite3 +0 -0
- data/test/dummy_app/log/test.log +26911 -21739
- data/test/dummy_app/tmp/2.0.1/integration/alt_xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/integration/csv.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/integration/ods.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/integration/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/kitchen_sink.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/kitchen_sink.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/{empty_sa.csv → 2.0.1/models/ActiveModelObject/empty.csv} +0 -0
- data/test/dummy_app/tmp/{ods/empty_model.ods → 2.0.1/models/ActiveModelObject/empty.ods} +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.csv +1 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.csv +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/empty.csv +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/empty.csv +0 -0
- data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/multi_sheet.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/multi_sheet.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/integration/alt_xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/integration/csv.csv +6 -0
- data/test/dummy_app/tmp/3.0.0.pre/integration/ods.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/integration/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/kitchen_sink.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/kitchen_sink.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.csv +3 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.csv +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.csv +6 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.csv +3 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.csv +1 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.csv +6 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.csv +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.csv +3 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.csv +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/data.csv +3 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/empty.csv +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/multi_sheet.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/multi_sheet.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/integration/alt_xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/integration/csv.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/integration/ods.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/integration/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/kitchen_sink.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/kitchen_sink.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.csv +3 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.csv +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.csv +3 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.csv +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/data.csv +3 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/empty.csv +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/data.csv +3 -0
- data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/empty.csv +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/multi_sheet.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/multi_sheet.xlsx +0 -0
- data/test/integration/application_test.rb +8 -11
- data/test/models/all_models_test.rb +107 -0
- data/test/test_helper.rb +13 -4
- data/test/unit/exceptions_test.rb +168 -0
- data/test/unit/formats_test.rb +15 -0
- data/test/unit/general_test.rb +15 -0
- data/test/unit/kitchen_sink_test.rb +87 -0
- data/test/unit/multi_sheet_test.rb +29 -0
- data/test/unit/utils_test.rb +179 -0
- data/test/unit/xlsx_utils_test.rb +143 -0
- metadata +409 -116
- data/lib/generators/spreadsheet_architect/add_project_defaults_generator.rb +0 -20
- data/test/dummy_app/app/models/bad_plain_ruby_object.rb +0 -3
- data/test/dummy_app/app/views/reports/sample.html.erb +0 -1
- data/test/dummy_app/log/development.log +0 -28
- data/test/dummy_app/tmp/active_model_object/csv.csv +0 -21
- data/test/dummy_app/tmp/active_model_object/ods.ods +0 -0
- data/test/dummy_app/tmp/active_model_object/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/custom_posts/csv.csv +0 -6
- data/test/dummy_app/tmp/custom_posts/empty.xlsx +0 -0
- data/test/dummy_app/tmp/custom_posts/ods.ods +0 -0
- data/test/dummy_app/tmp/custom_posts/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/empty_model.csv +0 -1
- data/test/dummy_app/tmp/empty_model.xlsx +0 -0
- data/test/dummy_app/tmp/empty_sa.xlsx +0 -0
- data/test/dummy_app/tmp/extreme.xlsx +0 -0
- data/test/dummy_app/tmp/integration_tests/alt_xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/integration_tests/csv.csv +0 -6
- data/test/dummy_app/tmp/integration_tests/ods.ods +0 -0
- data/test/dummy_app/tmp/integration_tests/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/model.csv +0 -6
- data/test/dummy_app/tmp/model.xlsx +0 -0
- data/test/dummy_app/tmp/ods/empty_sa.ods +0 -0
- data/test/dummy_app/tmp/ods/model.ods +0 -0
- data/test/dummy_app/tmp/ods/model_options.ods +0 -0
- data/test/dummy_app/tmp/ods/sa.ods +0 -0
- data/test/dummy_app/tmp/options.csv +0 -6
- data/test/dummy_app/tmp/plain_ruby_object/csv.csv +0 -4
- data/test/dummy_app/tmp/plain_ruby_object/ods.ods +0 -0
- data/test/dummy_app/tmp/plain_ruby_object/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/posts/csv.csv +0 -6
- data/test/dummy_app/tmp/posts/empty.xlsx +0 -0
- data/test/dummy_app/tmp/posts/ods.ods +0 -0
- data/test/dummy_app/tmp/posts/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/sa.csv +0 -4
- data/test/dummy_app/tmp/sa.xlsx +0 -0
- data/test/models/active_model_object_test.rb +0 -51
- data/test/models/bad_plain_ruby_object_test.rb +0 -28
- data/test/models/csv_test.rb +0 -59
- data/test/models/custom_post_test.rb +0 -51
- data/test/models/ods_test.rb +0 -65
- data/test/models/plain_ruby_object_test.rb +0 -51
- data/test/models/post_test.rb +0 -44
- data/test/models/spreadsheet_architect_utils_test.rb +0 -73
- data/test/models/xlsx_test.rb +0 -98
- data/test/spreadsheet_architect_test.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9373288a5139e4300488dc26c66aa5783ddca415a5a01c9b509b7e19a4716055
|
4
|
+
data.tar.gz: c8c58c68932e5fc5e36c3f73c3b5d106e90261a64bdbf046fa133e940c2fbb94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef1f1ac7cd4187c9dae74efcc001099cc190a39a11f7f15341c0649dfac21c13347f8f537274a664e6365229d31a32b58dc60786ea3f7127fdfd18828ba91175
|
7
|
+
data.tar.gz: 84b8abd050f5924b25ba15012dde4cd5500ad85de2fa16149c0d0eda0e3fa85ef49370a7d3d5f6a2f3c7ede3f176c6ca23fae02e811bf18711b3b6c3e2fbc09f
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,28 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
3
|
|
4
|
+
- **3.0.0** - July 6, 2018
|
5
|
+
- [#16](https://github.com/westonganger/spreadsheet_architect/issues/16) - Add ability to pass :instances option to SpreadsheetArchitect class methods
|
6
|
+
- [#16](https://github.com/westonganger/spreadsheet_architect/issues/16) - Remove Plain Ruby syntax `Post.to_xlsx(instances: posts_array)` in favor of `SpreadsheetArchitect.to_xlsx(instance: posts_array)`. However, it may still work at this time if configured correctly.
|
7
|
+
- Fix project-wide and model-level defaults before only `header_style`, `row_style`, & `sheet_name` were being utilized.
|
8
|
+
- When using on an ActiveRecord class and `spreadsheet_columns` is not defined, it now defaults to the classes `column_names` only. Previously it would use `column_names` and then remove the following columns `['id', 'created_at', 'updated_at', 'deleted_at']`
|
9
|
+
- XLSX column ranges now also accept letters. For example: `{columns: ('C'..'E')}`
|
10
|
+
- `:column_types` now considers types defined in `spreadsheet_columns` and class/project-wide defaults. Before it was incorrectly ignored.
|
11
|
+
- Passing the `spreadsheet_columns` options now only accepts lambda/proc
|
12
|
+
- More type checking and Option types are now being type checked. Option types were supposed to be properly type checked but due to a bug were being skipped.
|
13
|
+
- Utilize ActiveSupport `pluralize`, if available, for default sheet names for class-based spreadsheets
|
14
|
+
- Renamed `BadRangeError` to `InvalidRangeError`
|
15
|
+
- Renamed `IncorrectTypeError` to `InvalidTypeError`
|
16
|
+
- Remove all Rails generators `spreadsheet_architect:add_default_options`. No need since its just as easy to copy from the README
|
17
|
+
- Major overhaul of test suite, add a ton more tests, for DRYness use resursion for tests when appropriate
|
18
|
+
- Use appraisal to test various `axlsx` versions
|
4
19
|
- **2.1.2** - July 6, 2018
|
5
20
|
- Fix bug where everything was underlined by default in Excel (LibreOffice was working correctly). For some reason, `false` in `:u` or `:underline` was incorrectly being treated as `true` but only within Excel. Now anytime `false` is encountered for either `:u` or `:underline` it is now converted to `nil`
|
6
21
|
- Fix bug where empty xlsx spreadsheets were corrupt when trying to open with Excel (LibreOffice was working correctly). This only occured when containing no headers and empty `:data` option which resulted in a package with no sheets.
|
7
22
|
- **2.1.1** - July 4, 2018
|
8
|
-
- [
|
23
|
+
- [#18](https://github.com/westonganger/spreadsheet_architect/pull/18) - Fix controller bug when using an non-ActiveRecord ORM only within Rails
|
9
24
|
- **2.1.0** - June 20, 2018
|
10
|
-
- [
|
25
|
+
- [#15](https://github.com/westonganger/spreadsheet_architect/pull/15) - Improved the method symbolize_keys. This method did not work properly for nested objects.
|
11
26
|
- [PR #15](https://github.com/westonganger/spreadsheet_architect/pull/15) - Added the ability to pass `:text_wrap` option within the `:alignment` style
|
12
27
|
- Make axlsx styles higher precendence over Spreadsheet Architect style aliases
|
13
28
|
- Use `prepend` monkey patches in Ruby 2+ to avoid annoying overwrite warnings when using old `define_method` monkey patches
|
data/README.md
CHANGED
@@ -1,92 +1,129 @@
|
|
1
1
|
# Spreadsheet Architect
|
2
2
|
|
3
|
-
<a href=
|
4
|
-
<a href='https://
|
3
|
+
<a href="https://badge.fury.io/rb/spreadsheet_architect" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/spreadsheet_architect.svg" alt="Gem Version"></a>
|
4
|
+
<a href='https://travis-ci.org/westonganger/spreadsheet_architect' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://api.travis-ci.org/westonganger/spreadsheet_architect.svg?branch=master' border='0' alt='Build Status' /></a>
|
5
|
+
<a href='https://rubygems.org/gems/spreadsheet_architect' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/spreadsheet_architect?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
|
6
|
+
<a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
|
5
7
|
|
6
|
-
Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets easily from ActiveRecord relations,
|
8
|
+
Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets super easily from ActiveRecord relations, plain Ruby objects, or tabular data.
|
7
9
|
|
8
10
|
Key Features:
|
9
11
|
|
10
|
-
- Can generate headers & columns from ActiveRecord column_names or a Class/Model's `spreadsheet_columns` method
|
11
12
|
- Dead simple custom spreadsheets with custom data
|
12
|
-
- Data Sources: ActiveRecord relations, array of Ruby
|
13
|
+
- Data Sources: ActiveRecord relations, array of plain Ruby object instances, or tabular 2D Array Data
|
13
14
|
- Easily style and customize spreadsheets
|
14
15
|
- Create multi sheet spreadsheets
|
15
16
|
- Setting Class/Model or Project specific defaults
|
16
17
|
- Simple to use ActionController renderers for Rails
|
17
|
-
- Plain Ruby (without Rails) supported
|
18
|
+
- Plain Ruby (without Rails) completely supported
|
18
19
|
|
19
|
-
|
20
|
+
# Install
|
20
21
|
```ruby
|
21
|
-
|
22
|
-
|
23
|
-
Post.order(name: :asc).where(published: true).to_ods
|
24
|
-
Post.order(name: :asc).where(published: true).to_csv
|
22
|
+
gem 'spreadsheet_architect'
|
23
|
+
```
|
25
24
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
Post.to_csv(instances: posts_array)
|
25
|
+
# General Usage
|
26
|
+
|
27
|
+
### Tabular (Array) Data
|
30
28
|
|
31
|
-
|
29
|
+
```ruby
|
32
30
|
headers = ['Col 1','Col 2','Col 3']
|
33
31
|
data = [[1,2,3], [4,5,6], [7,8,9]]
|
34
|
-
SpreadsheetArchitect.to_xlsx(
|
35
|
-
SpreadsheetArchitect.to_ods(
|
36
|
-
SpreadsheetArchitect.to_csv(
|
32
|
+
SpreadsheetArchitect.to_xlsx(headers: headers, data: data)
|
33
|
+
SpreadsheetArchitect.to_ods(headers: headers, data: data)
|
34
|
+
SpreadsheetArchitect.to_csv(headers: headers, data: data)
|
37
35
|
```
|
38
36
|
|
39
|
-
|
37
|
+
### Rails relation or an array of plain Ruby object instances
|
38
|
+
|
40
39
|
```ruby
|
41
|
-
|
42
|
-
|
40
|
+
posts = Post.order(name: :asc).where(published: true)
|
41
|
+
# OR
|
42
|
+
posts = 10.times.map{|i| Post.new(number: i)}
|
43
|
+
|
44
|
+
SpreadsheetArchitect.to_xlsx(instances: posts)
|
45
|
+
SpreadsheetArchitect.to_ods(instances: posts)
|
46
|
+
SpreadsheetArchitect.to_csv(instances: posts)
|
43
47
|
```
|
44
48
|
|
45
|
-
|
49
|
+
**(Optional)** If you would like to add the methods `to_xlsx`, `to_ods`, `to_csv`, `to_axlsx_package`, `to_rodf_spreadsheet` to some class, you can simply include the SpreadsheetArchitect module to whichever classes you choose. A good default strategy is to simply add it to the ApplicationRecord or another parent class to have it available on all appropriate classes. For example:
|
46
50
|
|
47
|
-
### Model
|
48
51
|
```ruby
|
49
|
-
class
|
52
|
+
class ApplicationRecord < ActiveRecord::Base
|
50
53
|
include SpreadsheetArchitect
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Then use it on the class or ActiveRecord relations of the class
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
posts = Post.order(name: :asc).where(published: true)
|
61
|
+
posts.to_xlsx
|
62
|
+
posts.to_ods
|
63
|
+
posts.to_csv
|
64
|
+
|
65
|
+
# Plain Ruby Objects
|
66
|
+
posts_array = 10.times.map{|i| Post.new(number: i)}
|
67
|
+
Post.to_xlsx(instances: posts_array)
|
68
|
+
Post.to_ods(instances: posts_array)
|
69
|
+
Post.to_csv(instances: posts_array)
|
70
|
+
```
|
71
|
+
|
72
|
+
# Usage with Instances / ActiveRecord Relations
|
51
73
|
|
52
|
-
|
53
|
-
|
54
|
-
|
74
|
+
When NOT using the `:data` option, ie. on an AR Relation or using the `:instances` option, Spreadsheet Architect requires an instance method defined on the class to generate the data. It looks for the `spreadsheet_columns` method on the class. If you are using on an ActiveRecord model and that method is not defined, it would fallback to the models `column_names` method (not recommended). If using the `:data` option this is ignored.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class Post
|
55
78
|
|
56
|
-
#optional for activerecord classes, defaults to the models column_names
|
57
79
|
def spreadsheet_columns
|
58
80
|
|
59
|
-
|
81
|
+
### Column format is: [Header, Cell Data / Method (if symbol) to Call on each Instance, (optional) Cell Type]
|
60
82
|
[
|
61
83
|
['Title', :title],
|
62
|
-
['Content', content],
|
84
|
+
['Content', content.strip],
|
63
85
|
['Author', (author.name if author)],
|
64
86
|
['Published?', (published ? 'Yes' : 'No')],
|
65
|
-
|
87
|
+
:published_at, # uses the method name as header title Ex. 'Published At'
|
66
88
|
['# of Views', :number_of_views, :float],
|
67
89
|
['Rating', :rating],
|
68
90
|
['Category/Tags', "#{category.name} - #{tags.collect(&:name).join(', ')}"]
|
69
91
|
]
|
92
|
+
end
|
93
|
+
```
|
70
94
|
|
71
|
-
|
72
|
-
[:title, :content, :published]
|
95
|
+
Alternatively, if `spreadsheet_columns` is passed as an option, this instance method does not need to be defined on the class. If defined on the class then naturally this will override it.
|
73
96
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
97
|
+
```ruby
|
98
|
+
Post.to_xlsx(instances: posts, spreadsheet_columns: Proc.new{|instance|
|
99
|
+
[
|
100
|
+
['Title', :title],
|
101
|
+
['Content', instance.content.strip],
|
102
|
+
['Author', (instance.author.name if instance.author)],
|
103
|
+
['Published?', (instance.published ? 'Yes' : 'No')],
|
104
|
+
:published_at, # uses the method name as header title Einstance. 'Published At'
|
105
|
+
['# of Views', :number_of_views, :float],
|
106
|
+
['Rating', :rating],
|
107
|
+
['Category/Tags', "#{instance.category.name} - #{instance.tags.collect(&:name).join(', ')}"]
|
108
|
+
]
|
109
|
+
})
|
78
110
|
```
|
79
111
|
|
80
|
-
|
112
|
+
# Sending & Saving Spreadsheets
|
81
113
|
|
82
|
-
|
114
|
+
### Method 1: Send Data via Rails Controller
|
83
115
|
|
84
|
-
### Method 1: Controller (for Rails)
|
85
116
|
```ruby
|
86
117
|
|
87
118
|
class PostsController < ActionController::Base
|
88
119
|
respond_to :html, :xlsx, :ods, :csv
|
89
120
|
|
121
|
+
def index
|
122
|
+
@posts = Post.order(published_at: :asc)
|
123
|
+
|
124
|
+
render xlsx: @posts
|
125
|
+
end
|
126
|
+
|
90
127
|
# Using respond_with
|
91
128
|
def index
|
92
129
|
@posts = Post.order(published_at: :asc)
|
@@ -132,116 +169,100 @@ end
|
|
132
169
|
```
|
133
170
|
|
134
171
|
### Method 2: Save to a file manually
|
172
|
+
|
135
173
|
```ruby
|
136
|
-
|
174
|
+
### Ex. with ActiveRecord relation
|
175
|
+
file_data = Post.order(published_at: :asc).to_xlsx
|
137
176
|
File.open('path/to/file.xlsx', 'w+b') do |f|
|
138
|
-
f.write
|
177
|
+
f.write file_data
|
139
178
|
end
|
179
|
+
|
180
|
+
file_data = Post.order(published_at: :asc).to_ods
|
140
181
|
File.open('path/to/file.ods', 'w+b') do |f|
|
141
|
-
f.write
|
182
|
+
f.write file_data
|
142
183
|
end
|
184
|
+
|
185
|
+
file_data = Post.order(published_at: :asc).to_csv
|
143
186
|
File.open('path/to/file.csv', 'w+b') do |f|
|
144
|
-
f.write
|
187
|
+
f.write file_data
|
145
188
|
end
|
189
|
+
```
|
146
190
|
|
147
|
-
#
|
148
|
-
|
149
|
-
|
150
|
-
|
191
|
+
# Multi Sheet XLSX Spreadsheets
|
192
|
+
```ruby
|
193
|
+
axlsx_package = SpreadsheetArchitect.to_axlsx_package({headers: headers, data: data})
|
194
|
+
axlsx_package = SpreadsheetArchitect.to_axlsx_package({headers: headers, data: data}, package)
|
151
195
|
|
152
|
-
# Ex. One time Usage
|
153
196
|
File.open('path/to/file.xlsx', 'w+b') do |f|
|
154
|
-
|
155
|
-
data = [[1,2,3], [4,5,6], [7,8,9]]
|
156
|
-
f.write SpreadsheetArchitect::to_xlsx(data: data, headers: headers)
|
197
|
+
f.write axlsx_package.to_stream.read
|
157
198
|
end
|
158
199
|
```
|
159
|
-
<br>
|
160
|
-
|
161
|
-
# Methods & Options
|
162
|
-
|
163
200
|
|
164
|
-
|
201
|
+
See this file for more details: https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/multi_sheet_test.rb
|
165
202
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|**headers**<br>*2D Array*|This defaults to your models custom spreadsheet_columns method or `self.column_names.collect(&:titleize)`|Pass `false` to skip the header row.|
|
171
|
-
|**sheet_name**<br>*String*|The class name||
|
172
|
-
|**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
|
173
|
-
|**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, format_code: nil}`|Styles for non-header rows. See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
|
174
|
-
|**column_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
|
175
|
-
|**range_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
|
176
|
-
|**merges**<br>*Array*||Merge cells. [See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
|
177
|
-
|**borders**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
|
178
|
-
|**column_widths**<br>*Array*||Sometimes you may want explicit column widths. Use nil if you want a column to autofit again.|
|
179
|
-
|
180
|
-
<br>
|
181
|
-
|
182
|
-
## SomeClass.to_ods
|
183
|
-
|
184
|
-
|Option|Default|Notes|
|
185
|
-
|---|---|---|
|
186
|
-
|**spreadsheet_columns**<br>*Array*| This defaults to your models custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Use this option to override the model instances `spreadsheet_columns` method|
|
187
|
-
|**instances**<br>*Array*| |**Required only for Non-ActiveRecord models** Array of class/model instances.|
|
188
|
-
|**headers**<br>*2D Array*|`self.column_names.collect(&:titleize)`|Pass `false` to skip the header row.|
|
189
|
-
|**sheet_name**<br>*String*|The class name||
|
190
|
-
|**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_size: 10, bold: true}`|Note: Currently ODS only supports these options (values can be changed though)|
|
191
|
-
|**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently ODS only supports these options|
|
192
|
-
|
193
|
-
<br>
|
203
|
+
### Multi Sheet ODS Spreadsheets
|
204
|
+
```ruby
|
205
|
+
ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data})
|
206
|
+
ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data}, spreadsheet)
|
194
207
|
|
195
|
-
|
208
|
+
File.open('path/to/file.ods', 'w+b') do |f|
|
209
|
+
f.write ods_spreadsheet
|
210
|
+
end
|
211
|
+
```
|
196
212
|
|
197
|
-
|
198
|
-
|---|---|---|
|
199
|
-
|**spreadsheet_columns**<br>*Array*| This defaults to your models custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Use this to option override the model instances `spreadsheet_columns` method|
|
200
|
-
|**instances**<br>*Array*| |**Required only for Non-ActiveRecord classes** Array of class/model instances.|
|
201
|
-
|**headers**<br>*2D Array*|`self.column_names.collect(&:titleize)`| Data for the header rows cells. Pass `false` to skip the header row.|
|
213
|
+
See this file for more details: https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/multi_sheet_test.rb
|
202
214
|
|
203
|
-
|
215
|
+
# Methods
|
204
216
|
|
205
|
-
##
|
217
|
+
## `to_xlsx(options={})`
|
206
218
|
|
207
219
|
|Option|Default|Notes|
|
208
220
|
|---|---|---|
|
209
|
-
|**data**<br>*Array*| |
|
210
|
-
|**
|
221
|
+
|**data**<br>*2D Array*| |Cannot be used with the `:instances` option.<br><br>Tabular data for the non-header row cells. |
|
222
|
+
|**instances**<br>*Array*| |Cannot be used with the `:data` option.<br><br>Array of class/model instances to be used as row data. Cannot be used with :data option|
|
223
|
+
|**spreadsheet_columns**<br>*Array*| If using the instances option or on a ActiveRecord relation, this defaults to the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Cannot be used with the `:data` option.<br><br>Use this option to override or define the spreadsheet columns. |
|
224
|
+
|**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. |
|
211
225
|
|**sheet_name**<br>*String*|`Sheet1`||
|
212
226
|
|**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
|
213
227
|
|**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, format_code: nil}`|Styles for non-header rows. See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
|
214
|
-
|**column_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/
|
215
|
-
|**range_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/
|
216
|
-
|**merges**<br>*Array*||Merge cells. [See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/
|
217
|
-
|**borders**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/
|
228
|
+
|**column_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb)|
|
229
|
+
|**range_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb)|
|
230
|
+
|**merges**<br>*Array*||Merge cells. [See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb). Warning merges cannot overlap eachother, if you attempt to do so Excel will claim your spreadsheet is corrupt and refuse to open your spreadsheet.|
|
231
|
+
|**borders**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb)|
|
218
232
|
|**column_types**<br>*Array*||Valid types for XLSX are :string, :integer, :float, :boolean, nil = auto determine.|
|
219
233
|
|**column_widths**<br>*Array*||Sometimes you may want explicit column widths. Use nil if you want a column to autofit again.|
|
220
|
-
|
221
|
-
<br>
|
222
234
|
|
223
|
-
##
|
235
|
+
## `to_axlsx_spreadsheet(options={}, axlsx_package_to_join=nil)`
|
236
|
+
Same options as `to_xlsx`. For more details
|
237
|
+
|
238
|
+
## `to_ods(options={})`
|
224
239
|
|
225
240
|
|Option|Default|Notes|
|
226
241
|
|---|---|---|
|
227
|
-
|**data**<br>*2D Array*| |
|
228
|
-
|**
|
242
|
+
|**data**<br>*2D Array*| |Cannot be used with the `:instances` option.<br><br>Tabular data for the non-header row cells. |
|
243
|
+
|**instances**<br>*Array*| |Cannot be used with the `:data` option.<br><br>Array of class/model instances to be used as row data. Cannot be used with :data option|
|
244
|
+
|**spreadsheet_columns**<br>*Array*| If using the instances option or on a ActiveRecord relation, this defaults to the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Cannot be used with the `:data` option.<br><br>Use this option to override or define the spreadsheet columns. |
|
245
|
+
|**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. |
|
229
246
|
|**sheet_name**<br>*String*|`Sheet1`||
|
230
247
|
|**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_size: 10, bold: true}`|Note: Currently ODS only supports these options|
|
231
248
|
|**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently ODS only supports these options|
|
232
|
-
|**column_types**<br>*Array*||Valid types for ODS are :string, :float
|
233
|
-
|
234
|
-
<br>
|
249
|
+
|**column_types**<br>*Array*||Valid types for ODS are :string, :float :percent, :currency, :date, :time,, nil = auto determine. Due to [RODF Issue #19](https://github.com/thiagoarrais/rodf/issues/19), :date/:time will be converted to :string |
|
235
250
|
|
236
|
-
##
|
251
|
+
## `to_rodf_spreadsheet(options={}, spreadsheet_to_join=nil)`
|
252
|
+
Same options as `to_ods`
|
253
|
+
|
254
|
+
## `to_csv(options={})`
|
237
255
|
|
238
256
|
|Option|Default|Notes|
|
239
257
|
|---|---|---|
|
240
|
-
|**data**<br>*2D Array*| |
|
241
|
-
|**
|
258
|
+
|**data**<br>*2D Array*| |Cannot be used with the `:instances` option.<br><br>Tabular data for the non-header row cells. |
|
259
|
+
|**instances**<br>*Array*| |Cannot be used with the `:data` option.<br><br>Array of class/model instances to be used as row data. Cannot be used with :data option|
|
260
|
+
|**spreadsheet_columns**<br>*Array*| If using the instances option or on a ActiveRecord relation, this defaults to the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Cannot be used with the `:data` option.<br><br>Use this option to override or define the spreadsheet columns. |
|
261
|
+
|**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. |
|
262
|
+
|
242
263
|
|
264
|
+
# Change class-wide default method options
|
243
265
|
|
244
|
-
# Change model default method options
|
245
266
|
```ruby
|
246
267
|
class Post
|
247
268
|
include SpreadsheetArchitect
|
@@ -262,12 +283,13 @@ class Post
|
|
262
283
|
range_styles: [],
|
263
284
|
merges: [],
|
264
285
|
borders: [],
|
265
|
-
column_types: []
|
286
|
+
column_types: [],
|
266
287
|
}
|
267
288
|
end
|
268
289
|
```
|
269
290
|
|
270
|
-
# Change project
|
291
|
+
# Change project-wide default method options
|
292
|
+
|
271
293
|
```ruby
|
272
294
|
# config/initializers/spreadsheet_architect.rb
|
273
295
|
|
@@ -280,33 +302,31 @@ SpreadsheetArchitect.default_options = {
|
|
280
302
|
range_styles: [],
|
281
303
|
merges: [],
|
282
304
|
borders: [],
|
283
|
-
column_types: []
|
305
|
+
column_types: [],
|
284
306
|
}
|
285
307
|
```
|
286
308
|
|
287
|
-
#
|
288
|
-
See this example: https://github.com/westonganger/spreadsheet_architect/blob/master/
|
309
|
+
# Kitchen Sink Examples with Styling for XLSX and ODS
|
310
|
+
See this example: https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb
|
289
311
|
|
312
|
+
# Axlsx Style Reference
|
290
313
|
|
291
|
-
|
292
|
-
```ruby
|
293
|
-
# Returns corresponding spreadsheet libraries object
|
294
|
-
package = SpreadsheetArchitect.to_axlsx_package({data: data, headers: headers})
|
295
|
-
SpreadsheetArchitect.to_axlsx_package({data: data, headers: headers}, package) # to combine two sheets to one file
|
314
|
+
I have compiled a list of all available style options for axlsx here: https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_style_reference.md
|
296
315
|
|
297
|
-
|
298
|
-
SpreadsheetArchitect.to_rodf_spreadsheet({data: data, headers: headers}, spreadsheet) # to combine two sheets to one file
|
299
|
-
```
|
316
|
+
# Testing / Validating your Spreadsheets
|
300
317
|
|
301
|
-
|
318
|
+
A wise word of advice, when testing your spreadsheets I recommend to use Excel instead of LibreOffice. This is because I have seen through testing, that where LibreOffice seems to just let most incorrect things just slide on through, Excel will not even open the spreadsheet as apparently it is much more strict about the spreadsheet validations. This will help you better identify any incorrect styling or customization issues.
|
302
319
|
|
320
|
+
# Contributing
|
303
321
|
|
304
|
-
|
305
|
-
I have compiled a list of all available style options for axlsx here: https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_style_reference.md
|
322
|
+
We use the `appraisal` gem for testing multiple versions of `axlsx`. Please use the following steps to test using `appraisal`.
|
306
323
|
|
324
|
+
1. `bundle exec appraisal install`
|
325
|
+
2. `bundle exec appraisal rake test`
|
307
326
|
|
308
327
|
# Credits
|
309
|
-
|
328
|
+
|
329
|
+
Created & Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger)
|
310
330
|
|
311
331
|
For any consulting or contract work please contact me via my company website: [Solid Foundation Web Development](https://solidfoundationwebdev.com)
|
312
332
|
|
@@ -3,8 +3,8 @@ require 'csv'
|
|
3
3
|
module SpreadsheetArchitect
|
4
4
|
module ClassMethods
|
5
5
|
def to_csv(opts={})
|
6
|
-
opts = SpreadsheetArchitect::Utils.
|
7
|
-
options = SpreadsheetArchitect::Utils.
|
6
|
+
opts = SpreadsheetArchitect::Utils.get_options(opts, self)
|
7
|
+
options = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
|
8
8
|
|
9
9
|
CSV.generate do |csv|
|
10
10
|
if options[:headers]
|
@@ -7,8 +7,8 @@ module SpreadsheetArchitect
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_rodf_spreadsheet(opts={}, spreadsheet=nil)
|
10
|
-
opts = SpreadsheetArchitect::Utils.
|
11
|
-
options = SpreadsheetArchitect::Utils.
|
10
|
+
opts = SpreadsheetArchitect::Utils.get_options(opts, self)
|
11
|
+
options = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
|
12
12
|
|
13
13
|
if !spreadsheet
|
14
14
|
spreadsheet = RODF::Spreadsheet.new
|
@@ -10,8 +10,8 @@ module SpreadsheetArchitect
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_axlsx_package(opts={}, package=nil)
|
13
|
-
opts = SpreadsheetArchitect::Utils.
|
14
|
-
options = SpreadsheetArchitect::Utils.
|
13
|
+
opts = SpreadsheetArchitect::Utils.get_options(opts, self)
|
14
|
+
options = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
|
15
15
|
|
16
16
|
header_style = SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(options[:header_style])
|
17
17
|
row_style = SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(options[:row_style])
|
@@ -93,18 +93,16 @@ module SpreadsheetArchitect
|
|
93
93
|
end
|
94
94
|
|
95
95
|
if options[:borders] || options[:column_styles] || options[:range_styles] || options[:merges]
|
96
|
-
col_names = max_row_length > 675 ? Array('A'..'ZZZ') : Array('A'..'ZZ')
|
97
96
|
num_rows = options[:data].count + (options[:headers] ? options[:headers].count : 0)
|
98
97
|
end
|
99
98
|
|
100
99
|
if options[:borders]
|
101
100
|
options[:borders].each do |x|
|
102
101
|
if x[:range].is_a?(Hash)
|
103
|
-
x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows
|
102
|
+
x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows)
|
103
|
+
else
|
104
|
+
SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows)
|
104
105
|
end
|
105
|
-
|
106
|
-
SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows, col_names)
|
107
|
-
sheet.add_border x[:range], x[:border_styles]
|
108
106
|
end
|
109
107
|
end
|
110
108
|
|
@@ -119,33 +117,29 @@ module SpreadsheetArchitect
|
|
119
117
|
package.workbook.styles do |s|
|
120
118
|
style = s.add_style row_style.merge(SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(x[:styles]))
|
121
119
|
|
122
|
-
|
120
|
+
case x[:columns]
|
121
|
+
when Array, Range
|
123
122
|
x[:columns].each do |col|
|
124
|
-
|
125
|
-
col = col_names.index(col)
|
126
|
-
end
|
123
|
+
SpreadsheetArchitect::Utils::XLSX.verify_column(col, max_row_length)
|
127
124
|
|
128
|
-
|
129
|
-
sheet.col_style(col, style, row_offset: start_row)
|
125
|
+
sheet.col_style(col, style, row_offset: start_row)
|
130
126
|
|
131
|
-
|
132
|
-
|
133
|
-
end
|
134
|
-
else
|
135
|
-
raise SpreadsheetArchitect::Exceptions::InvalidColumnError
|
127
|
+
if h_style
|
128
|
+
sheet.add_style("#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}1:#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}#{start_row}", h_style)
|
136
129
|
end
|
137
130
|
end
|
138
|
-
|
131
|
+
when Integer, String
|
139
132
|
col = x[:columns]
|
140
|
-
if col < max_row_length
|
141
|
-
sheet.col_style(x[:columns], style, row_offset: start_row)
|
142
133
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
134
|
+
SpreadsheetArchitect::Utils::XLSX.verify_column(col, max_row_length)
|
135
|
+
|
136
|
+
sheet.col_style(x[:columns], style, row_offset: start_row)
|
137
|
+
|
138
|
+
if h_style
|
139
|
+
sheet.add_style("#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}1:#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}#{start_row}", h_style)
|
148
140
|
end
|
141
|
+
else
|
142
|
+
SpreadsheetArchitect::Utils::XLSX.verify_column(x[:columns], max_row_length)
|
149
143
|
end
|
150
144
|
end
|
151
145
|
end
|
@@ -156,10 +150,11 @@ module SpreadsheetArchitect
|
|
156
150
|
styles = SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(x[:styles])
|
157
151
|
|
158
152
|
if x[:range].is_a?(Hash)
|
159
|
-
x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows
|
153
|
+
x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows)
|
154
|
+
else
|
155
|
+
SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows)
|
160
156
|
end
|
161
157
|
|
162
|
-
SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows, col_names)
|
163
158
|
sheet.add_style x[:range], styles
|
164
159
|
end
|
165
160
|
end
|
@@ -167,10 +162,11 @@ module SpreadsheetArchitect
|
|
167
162
|
if options[:merges]
|
168
163
|
options[:merges].each do |x|
|
169
164
|
if x[:range].is_a?(Hash)
|
170
|
-
x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows
|
165
|
+
x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows)
|
166
|
+
else
|
167
|
+
SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows)
|
171
168
|
end
|
172
169
|
|
173
|
-
SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows, col_names)
|
174
170
|
sheet.merge_cells x[:range]
|
175
171
|
end
|
176
172
|
end
|